001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchTeamException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.SQLQuery;
033    import com.liferay.portal.kernel.dao.orm.Session;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.util.GetterUtil;
038    import com.liferay.portal.kernel.util.InstanceFactory;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.SetUtil;
041    import com.liferay.portal.kernel.util.StringBundler;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.model.CacheModel;
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    /**
060     * The persistence implementation for the team service.
061     *
062     * <p>
063     * Caching information and settings can be found in <code>portal.properties</code>
064     * </p>
065     *
066     * @author Brian Wing Shun Chan
067     * @see TeamPersistence
068     * @see TeamUtil
069     * @generated
070     */
071    public class TeamPersistenceImpl extends BasePersistenceImpl<Team>
072            implements TeamPersistence {
073            /*
074             * NOTE FOR DEVELOPERS:
075             *
076             * Never modify or reference this class directly. Always use {@link TeamUtil} to access the team persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
077             */
078            public static final String FINDER_CLASS_NAME_ENTITY = TeamImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List1";
081            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List2";
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
084                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
086                            new String[] {
087                                    Long.class.getName(),
088                                    
089                            "java.lang.Integer", "java.lang.Integer",
090                                    "com.liferay.portal.kernel.util.OrderByComparator"
091                            });
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
093                    new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
094                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
096                            new String[] { Long.class.getName() },
097                            TeamModelImpl.GROUPID_COLUMN_BITMASK);
098            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
099                            TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
101                            new String[] { Long.class.getName() });
102            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
103                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
104                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
105                            new String[] { Long.class.getName(), String.class.getName() },
106                            TeamModelImpl.GROUPID_COLUMN_BITMASK |
107                            TeamModelImpl.NAME_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
109                            TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
111                            new String[] { Long.class.getName(), String.class.getName() });
112            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
113                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
115            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
116                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
117                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
118            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
119                            TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
121    
122            /**
123             * Caches the team in the entity cache if it is enabled.
124             *
125             * @param team the team
126             */
127            public void cacheResult(Team team) {
128                    EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
129                            TeamImpl.class, team.getPrimaryKey(), team);
130    
131                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
132                            new Object[] { Long.valueOf(team.getGroupId()), team.getName() },
133                            team);
134    
135                    team.resetOriginalValues();
136            }
137    
138            /**
139             * Caches the teams in the entity cache if it is enabled.
140             *
141             * @param teams the teams
142             */
143            public void cacheResult(List<Team> teams) {
144                    for (Team team : teams) {
145                            if (EntityCacheUtil.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
146                                                    TeamImpl.class, team.getPrimaryKey()) == null) {
147                                    cacheResult(team);
148                            }
149                            else {
150                                    team.resetOriginalValues();
151                            }
152                    }
153            }
154    
155            /**
156             * Clears the cache for all teams.
157             *
158             * <p>
159             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
160             * </p>
161             */
162            @Override
163            public void clearCache() {
164                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
165                            CacheRegistryUtil.clear(TeamImpl.class.getName());
166                    }
167    
168                    EntityCacheUtil.clearCache(TeamImpl.class.getName());
169    
170                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
171                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
172                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
173            }
174    
175            /**
176             * Clears the cache for the team.
177             *
178             * <p>
179             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
180             * </p>
181             */
182            @Override
183            public void clearCache(Team team) {
184                    EntityCacheUtil.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
185                            TeamImpl.class, team.getPrimaryKey());
186    
187                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
188                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
189    
190                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
191                            new Object[] { Long.valueOf(team.getGroupId()), team.getName() });
192            }
193    
194            /**
195             * Creates a new team with the primary key. Does not add the team to the database.
196             *
197             * @param teamId the primary key for the new team
198             * @return the new team
199             */
200            public Team create(long teamId) {
201                    Team team = new TeamImpl();
202    
203                    team.setNew(true);
204                    team.setPrimaryKey(teamId);
205    
206                    return team;
207            }
208    
209            /**
210             * Removes the team with the primary key from the database. Also notifies the appropriate model listeners.
211             *
212             * @param primaryKey the primary key of the team
213             * @return the team that was removed
214             * @throws com.liferay.portal.NoSuchModelException if a team with the primary key could not be found
215             * @throws SystemException if a system exception occurred
216             */
217            @Override
218            public Team remove(Serializable primaryKey)
219                    throws NoSuchModelException, SystemException {
220                    return remove(((Long)primaryKey).longValue());
221            }
222    
223            /**
224             * Removes the team with the primary key from the database. Also notifies the appropriate model listeners.
225             *
226             * @param teamId the primary key of the team
227             * @return the team that was removed
228             * @throws com.liferay.portal.NoSuchTeamException if a team with the primary key could not be found
229             * @throws SystemException if a system exception occurred
230             */
231            public Team remove(long teamId) throws NoSuchTeamException, SystemException {
232                    Session session = null;
233    
234                    try {
235                            session = openSession();
236    
237                            Team team = (Team)session.get(TeamImpl.class, Long.valueOf(teamId));
238    
239                            if (team == null) {
240                                    if (_log.isWarnEnabled()) {
241                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + teamId);
242                                    }
243    
244                                    throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
245                                            teamId);
246                            }
247    
248                            return teamPersistence.remove(team);
249                    }
250                    catch (NoSuchTeamException nsee) {
251                            throw nsee;
252                    }
253                    catch (Exception e) {
254                            throw processException(e);
255                    }
256                    finally {
257                            closeSession(session);
258                    }
259            }
260    
261            /**
262             * Removes the team from the database. Also notifies the appropriate model listeners.
263             *
264             * @param team the team
265             * @return the team that was removed
266             * @throws SystemException if a system exception occurred
267             */
268            @Override
269            public Team remove(Team team) throws SystemException {
270                    return super.remove(team);
271            }
272    
273            @Override
274            protected Team removeImpl(Team team) throws SystemException {
275                    team = toUnwrappedModel(team);
276    
277                    try {
278                            clearUsers.clear(team.getPrimaryKey());
279                    }
280                    catch (Exception e) {
281                            throw processException(e);
282                    }
283                    finally {
284                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
285                    }
286    
287                    try {
288                            clearUserGroups.clear(team.getPrimaryKey());
289                    }
290                    catch (Exception e) {
291                            throw processException(e);
292                    }
293                    finally {
294                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
295                    }
296    
297                    Session session = null;
298    
299                    try {
300                            session = openSession();
301    
302                            BatchSessionUtil.delete(session, team);
303                    }
304                    catch (Exception e) {
305                            throw processException(e);
306                    }
307                    finally {
308                            closeSession(session);
309                    }
310    
311                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
312                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
313    
314                    TeamModelImpl teamModelImpl = (TeamModelImpl)team;
315    
316                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
317                            new Object[] {
318                                    Long.valueOf(teamModelImpl.getGroupId()),
319                                    
320                            teamModelImpl.getName()
321                            });
322    
323                    EntityCacheUtil.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
324                            TeamImpl.class, team.getPrimaryKey());
325    
326                    return team;
327            }
328    
329            @Override
330            public Team updateImpl(com.liferay.portal.model.Team team, boolean merge)
331                    throws SystemException {
332                    team = toUnwrappedModel(team);
333    
334                    boolean isNew = team.isNew();
335    
336                    TeamModelImpl teamModelImpl = (TeamModelImpl)team;
337    
338                    Session session = null;
339    
340                    try {
341                            session = openSession();
342    
343                            BatchSessionUtil.update(session, team, merge);
344    
345                            team.setNew(false);
346                    }
347                    catch (Exception e) {
348                            throw processException(e);
349                    }
350                    finally {
351                            closeSession(session);
352                    }
353    
354                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
355    
356                    if (isNew || !TeamModelImpl.COLUMN_BITMASK_ENABLED) {
357                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
358                    }
359    
360                    else {
361                            if ((teamModelImpl.getColumnBitmask() &
362                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
363                                    Object[] args = new Object[] {
364                                                    Long.valueOf(teamModelImpl.getOriginalGroupId())
365                                            };
366    
367                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
368                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
369                                            args);
370    
371                                    args = new Object[] { Long.valueOf(teamModelImpl.getGroupId()) };
372    
373                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
374                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
375                                            args);
376                            }
377                    }
378    
379                    EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
380                            TeamImpl.class, team.getPrimaryKey(), team);
381    
382                    if (isNew) {
383                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
384                                    new Object[] { Long.valueOf(team.getGroupId()), team.getName() },
385                                    team);
386                    }
387                    else {
388                            if ((teamModelImpl.getColumnBitmask() &
389                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
390                                    Object[] args = new Object[] {
391                                                    Long.valueOf(teamModelImpl.getOriginalGroupId()),
392                                                    
393                                                    teamModelImpl.getOriginalName()
394                                            };
395    
396                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
397                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
398    
399                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
400                                            new Object[] { Long.valueOf(team.getGroupId()), team.getName() },
401                                            team);
402                            }
403                    }
404    
405                    return team;
406            }
407    
408            protected Team toUnwrappedModel(Team team) {
409                    if (team instanceof TeamImpl) {
410                            return team;
411                    }
412    
413                    TeamImpl teamImpl = new TeamImpl();
414    
415                    teamImpl.setNew(team.isNew());
416                    teamImpl.setPrimaryKey(team.getPrimaryKey());
417    
418                    teamImpl.setTeamId(team.getTeamId());
419                    teamImpl.setCompanyId(team.getCompanyId());
420                    teamImpl.setUserId(team.getUserId());
421                    teamImpl.setUserName(team.getUserName());
422                    teamImpl.setCreateDate(team.getCreateDate());
423                    teamImpl.setModifiedDate(team.getModifiedDate());
424                    teamImpl.setGroupId(team.getGroupId());
425                    teamImpl.setName(team.getName());
426                    teamImpl.setDescription(team.getDescription());
427    
428                    return teamImpl;
429            }
430    
431            /**
432             * Returns the team with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
433             *
434             * @param primaryKey the primary key of the team
435             * @return the team
436             * @throws com.liferay.portal.NoSuchModelException if a team with the primary key could not be found
437             * @throws SystemException if a system exception occurred
438             */
439            @Override
440            public Team findByPrimaryKey(Serializable primaryKey)
441                    throws NoSuchModelException, SystemException {
442                    return findByPrimaryKey(((Long)primaryKey).longValue());
443            }
444    
445            /**
446             * Returns the team with the primary key or throws a {@link com.liferay.portal.NoSuchTeamException} if it could not be found.
447             *
448             * @param teamId the primary key of the team
449             * @return the team
450             * @throws com.liferay.portal.NoSuchTeamException if a team with the primary key could not be found
451             * @throws SystemException if a system exception occurred
452             */
453            public Team findByPrimaryKey(long teamId)
454                    throws NoSuchTeamException, SystemException {
455                    Team team = fetchByPrimaryKey(teamId);
456    
457                    if (team == null) {
458                            if (_log.isWarnEnabled()) {
459                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + teamId);
460                            }
461    
462                            throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
463                                    teamId);
464                    }
465    
466                    return team;
467            }
468    
469            /**
470             * Returns the team with the primary key or returns <code>null</code> if it could not be found.
471             *
472             * @param primaryKey the primary key of the team
473             * @return the team, or <code>null</code> if a team with the primary key could not be found
474             * @throws SystemException if a system exception occurred
475             */
476            @Override
477            public Team fetchByPrimaryKey(Serializable primaryKey)
478                    throws SystemException {
479                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
480            }
481    
482            /**
483             * Returns the team with the primary key or returns <code>null</code> if it could not be found.
484             *
485             * @param teamId the primary key of the team
486             * @return the team, or <code>null</code> if a team with the primary key could not be found
487             * @throws SystemException if a system exception occurred
488             */
489            public Team fetchByPrimaryKey(long teamId) throws SystemException {
490                    Team team = (Team)EntityCacheUtil.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
491                                    TeamImpl.class, teamId);
492    
493                    if (team == _nullTeam) {
494                            return null;
495                    }
496    
497                    if (team == null) {
498                            Session session = null;
499    
500                            boolean hasException = false;
501    
502                            try {
503                                    session = openSession();
504    
505                                    team = (Team)session.get(TeamImpl.class, Long.valueOf(teamId));
506                            }
507                            catch (Exception e) {
508                                    hasException = true;
509    
510                                    throw processException(e);
511                            }
512                            finally {
513                                    if (team != null) {
514                                            cacheResult(team);
515                                    }
516                                    else if (!hasException) {
517                                            EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
518                                                    TeamImpl.class, teamId, _nullTeam);
519                                    }
520    
521                                    closeSession(session);
522                            }
523                    }
524    
525                    return team;
526            }
527    
528            /**
529             * Returns all the teams where groupId = &#63;.
530             *
531             * @param groupId the group ID
532             * @return the matching teams
533             * @throws SystemException if a system exception occurred
534             */
535            public List<Team> findByGroupId(long groupId) throws SystemException {
536                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
537            }
538    
539            /**
540             * Returns a range of all the teams where groupId = &#63;.
541             *
542             * <p>
543             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
544             * </p>
545             *
546             * @param groupId the group ID
547             * @param start the lower bound of the range of teams
548             * @param end the upper bound of the range of teams (not inclusive)
549             * @return the range of matching teams
550             * @throws SystemException if a system exception occurred
551             */
552            public List<Team> findByGroupId(long groupId, int start, int end)
553                    throws SystemException {
554                    return findByGroupId(groupId, start, end, null);
555            }
556    
557            /**
558             * Returns an ordered range of all the teams where groupId = &#63;.
559             *
560             * <p>
561             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
562             * </p>
563             *
564             * @param groupId the group ID
565             * @param start the lower bound of the range of teams
566             * @param end the upper bound of the range of teams (not inclusive)
567             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
568             * @return the ordered range of matching teams
569             * @throws SystemException if a system exception occurred
570             */
571            public List<Team> findByGroupId(long groupId, int start, int end,
572                    OrderByComparator orderByComparator) throws SystemException {
573                    FinderPath finderPath = null;
574                    Object[] finderArgs = null;
575    
576                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
577                                    (orderByComparator == null)) {
578                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
579                            finderArgs = new Object[] { groupId };
580                    }
581                    else {
582                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
583                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
584                    }
585    
586                    List<Team> list = (List<Team>)FinderCacheUtil.getResult(finderPath,
587                                    finderArgs, this);
588    
589                    if (list == null) {
590                            StringBundler query = null;
591    
592                            if (orderByComparator != null) {
593                                    query = new StringBundler(3 +
594                                                    (orderByComparator.getOrderByFields().length * 3));
595                            }
596                            else {
597                                    query = new StringBundler(3);
598                            }
599    
600                            query.append(_SQL_SELECT_TEAM_WHERE);
601    
602                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
603    
604                            if (orderByComparator != null) {
605                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
606                                            orderByComparator);
607                            }
608    
609                            else {
610                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
611                            }
612    
613                            String sql = query.toString();
614    
615                            Session session = null;
616    
617                            try {
618                                    session = openSession();
619    
620                                    Query q = session.createQuery(sql);
621    
622                                    QueryPos qPos = QueryPos.getInstance(q);
623    
624                                    qPos.add(groupId);
625    
626                                    list = (List<Team>)QueryUtil.list(q, getDialect(), start, end);
627                            }
628                            catch (Exception e) {
629                                    throw processException(e);
630                            }
631                            finally {
632                                    if (list == null) {
633                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
634                                    }
635                                    else {
636                                            cacheResult(list);
637    
638                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
639                                    }
640    
641                                    closeSession(session);
642                            }
643                    }
644    
645                    return list;
646            }
647    
648            /**
649             * Returns the first team in the ordered set where groupId = &#63;.
650             *
651             * <p>
652             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
653             * </p>
654             *
655             * @param groupId the group ID
656             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
657             * @return the first matching team
658             * @throws com.liferay.portal.NoSuchTeamException if a matching team could not be found
659             * @throws SystemException if a system exception occurred
660             */
661            public Team findByGroupId_First(long groupId,
662                    OrderByComparator orderByComparator)
663                    throws NoSuchTeamException, SystemException {
664                    List<Team> list = findByGroupId(groupId, 0, 1, orderByComparator);
665    
666                    if (list.isEmpty()) {
667                            StringBundler msg = new StringBundler(4);
668    
669                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
670    
671                            msg.append("groupId=");
672                            msg.append(groupId);
673    
674                            msg.append(StringPool.CLOSE_CURLY_BRACE);
675    
676                            throw new NoSuchTeamException(msg.toString());
677                    }
678                    else {
679                            return list.get(0);
680                    }
681            }
682    
683            /**
684             * Returns the last team in the ordered set where groupId = &#63;.
685             *
686             * <p>
687             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
688             * </p>
689             *
690             * @param groupId the group ID
691             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
692             * @return the last matching team
693             * @throws com.liferay.portal.NoSuchTeamException if a matching team could not be found
694             * @throws SystemException if a system exception occurred
695             */
696            public Team findByGroupId_Last(long groupId,
697                    OrderByComparator orderByComparator)
698                    throws NoSuchTeamException, SystemException {
699                    int count = countByGroupId(groupId);
700    
701                    List<Team> list = findByGroupId(groupId, count - 1, count,
702                                    orderByComparator);
703    
704                    if (list.isEmpty()) {
705                            StringBundler msg = new StringBundler(4);
706    
707                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
708    
709                            msg.append("groupId=");
710                            msg.append(groupId);
711    
712                            msg.append(StringPool.CLOSE_CURLY_BRACE);
713    
714                            throw new NoSuchTeamException(msg.toString());
715                    }
716                    else {
717                            return list.get(0);
718                    }
719            }
720    
721            /**
722             * Returns the teams before and after the current team in the ordered set where groupId = &#63;.
723             *
724             * <p>
725             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
726             * </p>
727             *
728             * @param teamId the primary key of the current team
729             * @param groupId the group ID
730             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
731             * @return the previous, current, and next team
732             * @throws com.liferay.portal.NoSuchTeamException if a team with the primary key could not be found
733             * @throws SystemException if a system exception occurred
734             */
735            public Team[] findByGroupId_PrevAndNext(long teamId, long groupId,
736                    OrderByComparator orderByComparator)
737                    throws NoSuchTeamException, SystemException {
738                    Team team = findByPrimaryKey(teamId);
739    
740                    Session session = null;
741    
742                    try {
743                            session = openSession();
744    
745                            Team[] array = new TeamImpl[3];
746    
747                            array[0] = getByGroupId_PrevAndNext(session, team, groupId,
748                                            orderByComparator, true);
749    
750                            array[1] = team;
751    
752                            array[2] = getByGroupId_PrevAndNext(session, team, groupId,
753                                            orderByComparator, false);
754    
755                            return array;
756                    }
757                    catch (Exception e) {
758                            throw processException(e);
759                    }
760                    finally {
761                            closeSession(session);
762                    }
763            }
764    
765            protected Team getByGroupId_PrevAndNext(Session session, Team team,
766                    long groupId, OrderByComparator orderByComparator, boolean previous) {
767                    StringBundler query = null;
768    
769                    if (orderByComparator != null) {
770                            query = new StringBundler(6 +
771                                            (orderByComparator.getOrderByFields().length * 6));
772                    }
773                    else {
774                            query = new StringBundler(3);
775                    }
776    
777                    query.append(_SQL_SELECT_TEAM_WHERE);
778    
779                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
780    
781                    if (orderByComparator != null) {
782                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
783    
784                            if (orderByConditionFields.length > 0) {
785                                    query.append(WHERE_AND);
786                            }
787    
788                            for (int i = 0; i < orderByConditionFields.length; i++) {
789                                    query.append(_ORDER_BY_ENTITY_ALIAS);
790                                    query.append(orderByConditionFields[i]);
791    
792                                    if ((i + 1) < orderByConditionFields.length) {
793                                            if (orderByComparator.isAscending() ^ previous) {
794                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
795                                            }
796                                            else {
797                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
798                                            }
799                                    }
800                                    else {
801                                            if (orderByComparator.isAscending() ^ previous) {
802                                                    query.append(WHERE_GREATER_THAN);
803                                            }
804                                            else {
805                                                    query.append(WHERE_LESSER_THAN);
806                                            }
807                                    }
808                            }
809    
810                            query.append(ORDER_BY_CLAUSE);
811    
812                            String[] orderByFields = orderByComparator.getOrderByFields();
813    
814                            for (int i = 0; i < orderByFields.length; i++) {
815                                    query.append(_ORDER_BY_ENTITY_ALIAS);
816                                    query.append(orderByFields[i]);
817    
818                                    if ((i + 1) < orderByFields.length) {
819                                            if (orderByComparator.isAscending() ^ previous) {
820                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
821                                            }
822                                            else {
823                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
824                                            }
825                                    }
826                                    else {
827                                            if (orderByComparator.isAscending() ^ previous) {
828                                                    query.append(ORDER_BY_ASC);
829                                            }
830                                            else {
831                                                    query.append(ORDER_BY_DESC);
832                                            }
833                                    }
834                            }
835                    }
836    
837                    else {
838                            query.append(TeamModelImpl.ORDER_BY_JPQL);
839                    }
840    
841                    String sql = query.toString();
842    
843                    Query q = session.createQuery(sql);
844    
845                    q.setFirstResult(0);
846                    q.setMaxResults(2);
847    
848                    QueryPos qPos = QueryPos.getInstance(q);
849    
850                    qPos.add(groupId);
851    
852                    if (orderByComparator != null) {
853                            Object[] values = orderByComparator.getOrderByConditionValues(team);
854    
855                            for (Object value : values) {
856                                    qPos.add(value);
857                            }
858                    }
859    
860                    List<Team> list = q.list();
861    
862                    if (list.size() == 2) {
863                            return list.get(1);
864                    }
865                    else {
866                            return null;
867                    }
868            }
869    
870            /**
871             * Returns all the teams that the user has permission to view where groupId = &#63;.
872             *
873             * @param groupId the group ID
874             * @return the matching teams that the user has permission to view
875             * @throws SystemException if a system exception occurred
876             */
877            public List<Team> filterFindByGroupId(long groupId)
878                    throws SystemException {
879                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
880                            QueryUtil.ALL_POS, null);
881            }
882    
883            /**
884             * Returns a range of all the teams that the user has permission to view where groupId = &#63;.
885             *
886             * <p>
887             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
888             * </p>
889             *
890             * @param groupId the group ID
891             * @param start the lower bound of the range of teams
892             * @param end the upper bound of the range of teams (not inclusive)
893             * @return the range of matching teams that the user has permission to view
894             * @throws SystemException if a system exception occurred
895             */
896            public List<Team> filterFindByGroupId(long groupId, int start, int end)
897                    throws SystemException {
898                    return filterFindByGroupId(groupId, start, end, null);
899            }
900    
901            /**
902             * Returns an ordered range of all the teams that the user has permissions to view where groupId = &#63;.
903             *
904             * <p>
905             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
906             * </p>
907             *
908             * @param groupId the group ID
909             * @param start the lower bound of the range of teams
910             * @param end the upper bound of the range of teams (not inclusive)
911             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
912             * @return the ordered range of matching teams that the user has permission to view
913             * @throws SystemException if a system exception occurred
914             */
915            public List<Team> filterFindByGroupId(long groupId, int start, int end,
916                    OrderByComparator orderByComparator) throws SystemException {
917                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
918                            return findByGroupId(groupId, start, end, orderByComparator);
919                    }
920    
921                    StringBundler query = null;
922    
923                    if (orderByComparator != null) {
924                            query = new StringBundler(3 +
925                                            (orderByComparator.getOrderByFields().length * 3));
926                    }
927                    else {
928                            query = new StringBundler(3);
929                    }
930    
931                    if (getDB().isSupportsInlineDistinct()) {
932                            query.append(_FILTER_SQL_SELECT_TEAM_WHERE);
933                    }
934                    else {
935                            query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_1);
936                    }
937    
938                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
939    
940                    if (!getDB().isSupportsInlineDistinct()) {
941                            query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_2);
942                    }
943    
944                    if (orderByComparator != null) {
945                            if (getDB().isSupportsInlineDistinct()) {
946                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
947                                            orderByComparator);
948                            }
949                            else {
950                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
951                                            orderByComparator);
952                            }
953                    }
954    
955                    else {
956                            if (getDB().isSupportsInlineDistinct()) {
957                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
958                            }
959                            else {
960                                    query.append(TeamModelImpl.ORDER_BY_SQL);
961                            }
962                    }
963    
964                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
965                                    Team.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
966                                    groupId);
967    
968                    Session session = null;
969    
970                    try {
971                            session = openSession();
972    
973                            SQLQuery q = session.createSQLQuery(sql);
974    
975                            if (getDB().isSupportsInlineDistinct()) {
976                                    q.addEntity(_FILTER_ENTITY_ALIAS, TeamImpl.class);
977                            }
978                            else {
979                                    q.addEntity(_FILTER_ENTITY_TABLE, TeamImpl.class);
980                            }
981    
982                            QueryPos qPos = QueryPos.getInstance(q);
983    
984                            qPos.add(groupId);
985    
986                            return (List<Team>)QueryUtil.list(q, getDialect(), start, end);
987                    }
988                    catch (Exception e) {
989                            throw processException(e);
990                    }
991                    finally {
992                            closeSession(session);
993                    }
994            }
995    
996            /**
997             * Returns the teams before and after the current team in the ordered set of teams that the user has permission to view where groupId = &#63;.
998             *
999             * @param teamId the primary key of the current team
1000             * @param groupId the group ID
1001             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1002             * @return the previous, current, and next team
1003             * @throws com.liferay.portal.NoSuchTeamException if a team with the primary key could not be found
1004             * @throws SystemException if a system exception occurred
1005             */
1006            public Team[] filterFindByGroupId_PrevAndNext(long teamId, long groupId,
1007                    OrderByComparator orderByComparator)
1008                    throws NoSuchTeamException, SystemException {
1009                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1010                            return findByGroupId_PrevAndNext(teamId, groupId, orderByComparator);
1011                    }
1012    
1013                    Team team = findByPrimaryKey(teamId);
1014    
1015                    Session session = null;
1016    
1017                    try {
1018                            session = openSession();
1019    
1020                            Team[] array = new TeamImpl[3];
1021    
1022                            array[0] = filterGetByGroupId_PrevAndNext(session, team, groupId,
1023                                            orderByComparator, true);
1024    
1025                            array[1] = team;
1026    
1027                            array[2] = filterGetByGroupId_PrevAndNext(session, team, groupId,
1028                                            orderByComparator, false);
1029    
1030                            return array;
1031                    }
1032                    catch (Exception e) {
1033                            throw processException(e);
1034                    }
1035                    finally {
1036                            closeSession(session);
1037                    }
1038            }
1039    
1040            protected Team filterGetByGroupId_PrevAndNext(Session session, Team team,
1041                    long groupId, OrderByComparator orderByComparator, boolean previous) {
1042                    StringBundler query = null;
1043    
1044                    if (orderByComparator != null) {
1045                            query = new StringBundler(6 +
1046                                            (orderByComparator.getOrderByFields().length * 6));
1047                    }
1048                    else {
1049                            query = new StringBundler(3);
1050                    }
1051    
1052                    if (getDB().isSupportsInlineDistinct()) {
1053                            query.append(_FILTER_SQL_SELECT_TEAM_WHERE);
1054                    }
1055                    else {
1056                            query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_1);
1057                    }
1058    
1059                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1060    
1061                    if (!getDB().isSupportsInlineDistinct()) {
1062                            query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_2);
1063                    }
1064    
1065                    if (orderByComparator != null) {
1066                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1067    
1068                            if (orderByConditionFields.length > 0) {
1069                                    query.append(WHERE_AND);
1070                            }
1071    
1072                            for (int i = 0; i < orderByConditionFields.length; i++) {
1073                                    if (getDB().isSupportsInlineDistinct()) {
1074                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1075                                    }
1076                                    else {
1077                                            query.append(_ORDER_BY_ENTITY_TABLE);
1078                                    }
1079    
1080                                    query.append(orderByConditionFields[i]);
1081    
1082                                    if ((i + 1) < orderByConditionFields.length) {
1083                                            if (orderByComparator.isAscending() ^ previous) {
1084                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1085                                            }
1086                                            else {
1087                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1088                                            }
1089                                    }
1090                                    else {
1091                                            if (orderByComparator.isAscending() ^ previous) {
1092                                                    query.append(WHERE_GREATER_THAN);
1093                                            }
1094                                            else {
1095                                                    query.append(WHERE_LESSER_THAN);
1096                                            }
1097                                    }
1098                            }
1099    
1100                            query.append(ORDER_BY_CLAUSE);
1101    
1102                            String[] orderByFields = orderByComparator.getOrderByFields();
1103    
1104                            for (int i = 0; i < orderByFields.length; i++) {
1105                                    if (getDB().isSupportsInlineDistinct()) {
1106                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1107                                    }
1108                                    else {
1109                                            query.append(_ORDER_BY_ENTITY_TABLE);
1110                                    }
1111    
1112                                    query.append(orderByFields[i]);
1113    
1114                                    if ((i + 1) < orderByFields.length) {
1115                                            if (orderByComparator.isAscending() ^ previous) {
1116                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1117                                            }
1118                                            else {
1119                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1120                                            }
1121                                    }
1122                                    else {
1123                                            if (orderByComparator.isAscending() ^ previous) {
1124                                                    query.append(ORDER_BY_ASC);
1125                                            }
1126                                            else {
1127                                                    query.append(ORDER_BY_DESC);
1128                                            }
1129                                    }
1130                            }
1131                    }
1132    
1133                    else {
1134                            if (getDB().isSupportsInlineDistinct()) {
1135                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
1136                            }
1137                            else {
1138                                    query.append(TeamModelImpl.ORDER_BY_SQL);
1139                            }
1140                    }
1141    
1142                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1143                                    Team.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
1144                                    groupId);
1145    
1146                    SQLQuery q = session.createSQLQuery(sql);
1147    
1148                    q.setFirstResult(0);
1149                    q.setMaxResults(2);
1150    
1151                    if (getDB().isSupportsInlineDistinct()) {
1152                            q.addEntity(_FILTER_ENTITY_ALIAS, TeamImpl.class);
1153                    }
1154                    else {
1155                            q.addEntity(_FILTER_ENTITY_TABLE, TeamImpl.class);
1156                    }
1157    
1158                    QueryPos qPos = QueryPos.getInstance(q);
1159    
1160                    qPos.add(groupId);
1161    
1162                    if (orderByComparator != null) {
1163                            Object[] values = orderByComparator.getOrderByConditionValues(team);
1164    
1165                            for (Object value : values) {
1166                                    qPos.add(value);
1167                            }
1168                    }
1169    
1170                    List<Team> list = q.list();
1171    
1172                    if (list.size() == 2) {
1173                            return list.get(1);
1174                    }
1175                    else {
1176                            return null;
1177                    }
1178            }
1179    
1180            /**
1181             * Returns the team where groupId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchTeamException} if it could not be found.
1182             *
1183             * @param groupId the group ID
1184             * @param name the name
1185             * @return the matching team
1186             * @throws com.liferay.portal.NoSuchTeamException if a matching team could not be found
1187             * @throws SystemException if a system exception occurred
1188             */
1189            public Team findByG_N(long groupId, String name)
1190                    throws NoSuchTeamException, SystemException {
1191                    Team team = fetchByG_N(groupId, name);
1192    
1193                    if (team == null) {
1194                            StringBundler msg = new StringBundler(6);
1195    
1196                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1197    
1198                            msg.append("groupId=");
1199                            msg.append(groupId);
1200    
1201                            msg.append(", name=");
1202                            msg.append(name);
1203    
1204                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1205    
1206                            if (_log.isWarnEnabled()) {
1207                                    _log.warn(msg.toString());
1208                            }
1209    
1210                            throw new NoSuchTeamException(msg.toString());
1211                    }
1212    
1213                    return team;
1214            }
1215    
1216            /**
1217             * Returns the team where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1218             *
1219             * @param groupId the group ID
1220             * @param name the name
1221             * @return the matching team, or <code>null</code> if a matching team could not be found
1222             * @throws SystemException if a system exception occurred
1223             */
1224            public Team fetchByG_N(long groupId, String name) throws SystemException {
1225                    return fetchByG_N(groupId, name, true);
1226            }
1227    
1228            /**
1229             * Returns the team where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1230             *
1231             * @param groupId the group ID
1232             * @param name the name
1233             * @param retrieveFromCache whether to use the finder cache
1234             * @return the matching team, or <code>null</code> if a matching team could not be found
1235             * @throws SystemException if a system exception occurred
1236             */
1237            public Team fetchByG_N(long groupId, String name, boolean retrieveFromCache)
1238                    throws SystemException {
1239                    Object[] finderArgs = new Object[] { groupId, name };
1240    
1241                    Object result = null;
1242    
1243                    if (retrieveFromCache) {
1244                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
1245                                            finderArgs, this);
1246                    }
1247    
1248                    if (result == null) {
1249                            StringBundler query = new StringBundler(4);
1250    
1251                            query.append(_SQL_SELECT_TEAM_WHERE);
1252    
1253                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1254    
1255                            if (name == null) {
1256                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1257                            }
1258                            else {
1259                                    if (name.equals(StringPool.BLANK)) {
1260                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
1261                                    }
1262                                    else {
1263                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
1264                                    }
1265                            }
1266    
1267                            query.append(TeamModelImpl.ORDER_BY_JPQL);
1268    
1269                            String sql = query.toString();
1270    
1271                            Session session = null;
1272    
1273                            try {
1274                                    session = openSession();
1275    
1276                                    Query q = session.createQuery(sql);
1277    
1278                                    QueryPos qPos = QueryPos.getInstance(q);
1279    
1280                                    qPos.add(groupId);
1281    
1282                                    if (name != null) {
1283                                            qPos.add(name);
1284                                    }
1285    
1286                                    List<Team> list = q.list();
1287    
1288                                    result = list;
1289    
1290                                    Team team = null;
1291    
1292                                    if (list.isEmpty()) {
1293                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1294                                                    finderArgs, list);
1295                                    }
1296                                    else {
1297                                            team = list.get(0);
1298    
1299                                            cacheResult(team);
1300    
1301                                            if ((team.getGroupId() != groupId) ||
1302                                                            (team.getName() == null) ||
1303                                                            !team.getName().equals(name)) {
1304                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1305                                                            finderArgs, team);
1306                                            }
1307                                    }
1308    
1309                                    return team;
1310                            }
1311                            catch (Exception e) {
1312                                    throw processException(e);
1313                            }
1314                            finally {
1315                                    if (result == null) {
1316                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
1317                                                    finderArgs);
1318                                    }
1319    
1320                                    closeSession(session);
1321                            }
1322                    }
1323                    else {
1324                            if (result instanceof List<?>) {
1325                                    return null;
1326                            }
1327                            else {
1328                                    return (Team)result;
1329                            }
1330                    }
1331            }
1332    
1333            /**
1334             * Returns all the teams.
1335             *
1336             * @return the teams
1337             * @throws SystemException if a system exception occurred
1338             */
1339            public List<Team> findAll() throws SystemException {
1340                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1341            }
1342    
1343            /**
1344             * Returns a range of all the teams.
1345             *
1346             * <p>
1347             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1348             * </p>
1349             *
1350             * @param start the lower bound of the range of teams
1351             * @param end the upper bound of the range of teams (not inclusive)
1352             * @return the range of teams
1353             * @throws SystemException if a system exception occurred
1354             */
1355            public List<Team> findAll(int start, int end) throws SystemException {
1356                    return findAll(start, end, null);
1357            }
1358    
1359            /**
1360             * Returns an ordered range of all the teams.
1361             *
1362             * <p>
1363             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1364             * </p>
1365             *
1366             * @param start the lower bound of the range of teams
1367             * @param end the upper bound of the range of teams (not inclusive)
1368             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1369             * @return the ordered range of teams
1370             * @throws SystemException if a system exception occurred
1371             */
1372            public List<Team> findAll(int start, int end,
1373                    OrderByComparator orderByComparator) throws SystemException {
1374                    FinderPath finderPath = null;
1375                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1376    
1377                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1378                                    (orderByComparator == null)) {
1379                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1380                            finderArgs = FINDER_ARGS_EMPTY;
1381                    }
1382                    else {
1383                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1384                            finderArgs = new Object[] { start, end, orderByComparator };
1385                    }
1386    
1387                    List<Team> list = (List<Team>)FinderCacheUtil.getResult(finderPath,
1388                                    finderArgs, this);
1389    
1390                    if (list == null) {
1391                            StringBundler query = null;
1392                            String sql = null;
1393    
1394                            if (orderByComparator != null) {
1395                                    query = new StringBundler(2 +
1396                                                    (orderByComparator.getOrderByFields().length * 3));
1397    
1398                                    query.append(_SQL_SELECT_TEAM);
1399    
1400                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1401                                            orderByComparator);
1402    
1403                                    sql = query.toString();
1404                            }
1405                            else {
1406                                    sql = _SQL_SELECT_TEAM.concat(TeamModelImpl.ORDER_BY_JPQL);
1407                            }
1408    
1409                            Session session = null;
1410    
1411                            try {
1412                                    session = openSession();
1413    
1414                                    Query q = session.createQuery(sql);
1415    
1416                                    if (orderByComparator == null) {
1417                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1418                                                            end, false);
1419    
1420                                            Collections.sort(list);
1421                                    }
1422                                    else {
1423                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1424                                                            end);
1425                                    }
1426                            }
1427                            catch (Exception e) {
1428                                    throw processException(e);
1429                            }
1430                            finally {
1431                                    if (list == null) {
1432                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1433                                    }
1434                                    else {
1435                                            cacheResult(list);
1436    
1437                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1438                                    }
1439    
1440                                    closeSession(session);
1441                            }
1442                    }
1443    
1444                    return list;
1445            }
1446    
1447            /**
1448             * Removes all the teams where groupId = &#63; from the database.
1449             *
1450             * @param groupId the group ID
1451             * @throws SystemException if a system exception occurred
1452             */
1453            public void removeByGroupId(long groupId) throws SystemException {
1454                    for (Team team : findByGroupId(groupId)) {
1455                            teamPersistence.remove(team);
1456                    }
1457            }
1458    
1459            /**
1460             * Removes the team where groupId = &#63; and name = &#63; from the database.
1461             *
1462             * @param groupId the group ID
1463             * @param name the name
1464             * @throws SystemException if a system exception occurred
1465             */
1466            public void removeByG_N(long groupId, String name)
1467                    throws NoSuchTeamException, SystemException {
1468                    Team team = findByG_N(groupId, name);
1469    
1470                    teamPersistence.remove(team);
1471            }
1472    
1473            /**
1474             * Removes all the teams from the database.
1475             *
1476             * @throws SystemException if a system exception occurred
1477             */
1478            public void removeAll() throws SystemException {
1479                    for (Team team : findAll()) {
1480                            teamPersistence.remove(team);
1481                    }
1482            }
1483    
1484            /**
1485             * Returns the number of teams where groupId = &#63;.
1486             *
1487             * @param groupId the group ID
1488             * @return the number of matching teams
1489             * @throws SystemException if a system exception occurred
1490             */
1491            public int countByGroupId(long groupId) throws SystemException {
1492                    Object[] finderArgs = new Object[] { groupId };
1493    
1494                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1495                                    finderArgs, this);
1496    
1497                    if (count == null) {
1498                            StringBundler query = new StringBundler(2);
1499    
1500                            query.append(_SQL_COUNT_TEAM_WHERE);
1501    
1502                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1503    
1504                            String sql = query.toString();
1505    
1506                            Session session = null;
1507    
1508                            try {
1509                                    session = openSession();
1510    
1511                                    Query q = session.createQuery(sql);
1512    
1513                                    QueryPos qPos = QueryPos.getInstance(q);
1514    
1515                                    qPos.add(groupId);
1516    
1517                                    count = (Long)q.uniqueResult();
1518                            }
1519                            catch (Exception e) {
1520                                    throw processException(e);
1521                            }
1522                            finally {
1523                                    if (count == null) {
1524                                            count = Long.valueOf(0);
1525                                    }
1526    
1527                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1528                                            finderArgs, count);
1529    
1530                                    closeSession(session);
1531                            }
1532                    }
1533    
1534                    return count.intValue();
1535            }
1536    
1537            /**
1538             * Returns the number of teams that the user has permission to view where groupId = &#63;.
1539             *
1540             * @param groupId the group ID
1541             * @return the number of matching teams that the user has permission to view
1542             * @throws SystemException if a system exception occurred
1543             */
1544            public int filterCountByGroupId(long groupId) throws SystemException {
1545                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1546                            return countByGroupId(groupId);
1547                    }
1548    
1549                    StringBundler query = new StringBundler(2);
1550    
1551                    query.append(_FILTER_SQL_COUNT_TEAM_WHERE);
1552    
1553                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1554    
1555                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1556                                    Team.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
1557                                    groupId);
1558    
1559                    Session session = null;
1560    
1561                    try {
1562                            session = openSession();
1563    
1564                            SQLQuery q = session.createSQLQuery(sql);
1565    
1566                            q.addScalar(COUNT_COLUMN_NAME,
1567                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1568    
1569                            QueryPos qPos = QueryPos.getInstance(q);
1570    
1571                            qPos.add(groupId);
1572    
1573                            Long count = (Long)q.uniqueResult();
1574    
1575                            return count.intValue();
1576                    }
1577                    catch (Exception e) {
1578                            throw processException(e);
1579                    }
1580                    finally {
1581                            closeSession(session);
1582                    }
1583            }
1584    
1585            /**
1586             * Returns the number of teams where groupId = &#63; and name = &#63;.
1587             *
1588             * @param groupId the group ID
1589             * @param name the name
1590             * @return the number of matching teams
1591             * @throws SystemException if a system exception occurred
1592             */
1593            public int countByG_N(long groupId, String name) throws SystemException {
1594                    Object[] finderArgs = new Object[] { groupId, name };
1595    
1596                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1597                                    finderArgs, this);
1598    
1599                    if (count == null) {
1600                            StringBundler query = new StringBundler(3);
1601    
1602                            query.append(_SQL_COUNT_TEAM_WHERE);
1603    
1604                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1605    
1606                            if (name == null) {
1607                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1608                            }
1609                            else {
1610                                    if (name.equals(StringPool.BLANK)) {
1611                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
1612                                    }
1613                                    else {
1614                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
1615                                    }
1616                            }
1617    
1618                            String sql = query.toString();
1619    
1620                            Session session = null;
1621    
1622                            try {
1623                                    session = openSession();
1624    
1625                                    Query q = session.createQuery(sql);
1626    
1627                                    QueryPos qPos = QueryPos.getInstance(q);
1628    
1629                                    qPos.add(groupId);
1630    
1631                                    if (name != null) {
1632                                            qPos.add(name);
1633                                    }
1634    
1635                                    count = (Long)q.uniqueResult();
1636                            }
1637                            catch (Exception e) {
1638                                    throw processException(e);
1639                            }
1640                            finally {
1641                                    if (count == null) {
1642                                            count = Long.valueOf(0);
1643                                    }
1644    
1645                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
1646                                            count);
1647    
1648                                    closeSession(session);
1649                            }
1650                    }
1651    
1652                    return count.intValue();
1653            }
1654    
1655            /**
1656             * Returns the number of teams.
1657             *
1658             * @return the number of teams
1659             * @throws SystemException if a system exception occurred
1660             */
1661            public int countAll() throws SystemException {
1662                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1663                                    FINDER_ARGS_EMPTY, this);
1664    
1665                    if (count == null) {
1666                            Session session = null;
1667    
1668                            try {
1669                                    session = openSession();
1670    
1671                                    Query q = session.createQuery(_SQL_COUNT_TEAM);
1672    
1673                                    count = (Long)q.uniqueResult();
1674                            }
1675                            catch (Exception e) {
1676                                    throw processException(e);
1677                            }
1678                            finally {
1679                                    if (count == null) {
1680                                            count = Long.valueOf(0);
1681                                    }
1682    
1683                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1684                                            FINDER_ARGS_EMPTY, count);
1685    
1686                                    closeSession(session);
1687                            }
1688                    }
1689    
1690                    return count.intValue();
1691            }
1692    
1693            /**
1694             * Returns all the users associated with the team.
1695             *
1696             * @param pk the primary key of the team
1697             * @return the users associated with the team
1698             * @throws SystemException if a system exception occurred
1699             */
1700            public List<com.liferay.portal.model.User> getUsers(long pk)
1701                    throws SystemException {
1702                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1703            }
1704    
1705            /**
1706             * Returns a range of all the users associated with the team.
1707             *
1708             * <p>
1709             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1710             * </p>
1711             *
1712             * @param pk the primary key of the team
1713             * @param start the lower bound of the range of teams
1714             * @param end the upper bound of the range of teams (not inclusive)
1715             * @return the range of users associated with the team
1716             * @throws SystemException if a system exception occurred
1717             */
1718            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1719                    int end) throws SystemException {
1720                    return getUsers(pk, start, end, null);
1721            }
1722    
1723            public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1724                            TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS,
1725                            com.liferay.portal.model.impl.UserImpl.class,
1726                            TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "getUsers",
1727                            new String[] {
1728                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1729                                    "com.liferay.portal.kernel.util.OrderByComparator"
1730                            });
1731    
1732            /**
1733             * Returns an ordered range of all the users associated with the team.
1734             *
1735             * <p>
1736             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1737             * </p>
1738             *
1739             * @param pk the primary key of the team
1740             * @param start the lower bound of the range of teams
1741             * @param end the upper bound of the range of teams (not inclusive)
1742             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1743             * @return the ordered range of users associated with the team
1744             * @throws SystemException if a system exception occurred
1745             */
1746            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1747                    int end, OrderByComparator orderByComparator) throws SystemException {
1748                    Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
1749    
1750                    List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1751                                    finderArgs, this);
1752    
1753                    if (list == null) {
1754                            Session session = null;
1755    
1756                            try {
1757                                    session = openSession();
1758    
1759                                    String sql = null;
1760    
1761                                    if (orderByComparator != null) {
1762                                            sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
1763                                                                               .concat(orderByComparator.getOrderBy());
1764                                    }
1765                                    else {
1766                                            sql = _SQL_GETUSERS;
1767                                    }
1768    
1769                                    SQLQuery q = session.createSQLQuery(sql);
1770    
1771                                    q.addEntity("User_",
1772                                            com.liferay.portal.model.impl.UserImpl.class);
1773    
1774                                    QueryPos qPos = QueryPos.getInstance(q);
1775    
1776                                    qPos.add(pk);
1777    
1778                                    list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1779                                                    getDialect(), start, end);
1780                            }
1781                            catch (Exception e) {
1782                                    throw processException(e);
1783                            }
1784                            finally {
1785                                    if (list == null) {
1786                                            FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
1787                                                    finderArgs);
1788                                    }
1789                                    else {
1790                                            userPersistence.cacheResult(list);
1791    
1792                                            FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
1793                                                    finderArgs, list);
1794                                    }
1795    
1796                                    closeSession(session);
1797                            }
1798                    }
1799    
1800                    return list;
1801            }
1802    
1803            public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1804                            TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS, Long.class,
1805                            TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "getUsersSize",
1806                            new String[] { Long.class.getName() });
1807    
1808            /**
1809             * Returns the number of users associated with the team.
1810             *
1811             * @param pk the primary key of the team
1812             * @return the number of users associated with the team
1813             * @throws SystemException if a system exception occurred
1814             */
1815            public int getUsersSize(long pk) throws SystemException {
1816                    Object[] finderArgs = new Object[] { pk };
1817    
1818                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1819                                    finderArgs, this);
1820    
1821                    if (count == null) {
1822                            Session session = null;
1823    
1824                            try {
1825                                    session = openSession();
1826    
1827                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1828    
1829                                    q.addScalar(COUNT_COLUMN_NAME,
1830                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1831    
1832                                    QueryPos qPos = QueryPos.getInstance(q);
1833    
1834                                    qPos.add(pk);
1835    
1836                                    count = (Long)q.uniqueResult();
1837                            }
1838                            catch (Exception e) {
1839                                    throw processException(e);
1840                            }
1841                            finally {
1842                                    if (count == null) {
1843                                            count = Long.valueOf(0);
1844                                    }
1845    
1846                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1847                                            finderArgs, count);
1848    
1849                                    closeSession(session);
1850                            }
1851                    }
1852    
1853                    return count.intValue();
1854            }
1855    
1856            public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1857                            TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS, Boolean.class,
1858                            TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "containsUser",
1859                            new String[] { Long.class.getName(), Long.class.getName() });
1860    
1861            /**
1862             * Returns <code>true</code> if the user is associated with the team.
1863             *
1864             * @param pk the primary key of the team
1865             * @param userPK the primary key of the user
1866             * @return <code>true</code> if the user is associated with the team; <code>false</code> otherwise
1867             * @throws SystemException if a system exception occurred
1868             */
1869            public boolean containsUser(long pk, long userPK) throws SystemException {
1870                    Object[] finderArgs = new Object[] { pk, userPK };
1871    
1872                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1873                                    finderArgs, this);
1874    
1875                    if (value == null) {
1876                            try {
1877                                    value = Boolean.valueOf(containsUser.contains(pk, userPK));
1878                            }
1879                            catch (Exception e) {
1880                                    throw processException(e);
1881                            }
1882                            finally {
1883                                    if (value == null) {
1884                                            value = Boolean.FALSE;
1885                                    }
1886    
1887                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1888                                            finderArgs, value);
1889                            }
1890                    }
1891    
1892                    return value.booleanValue();
1893            }
1894    
1895            /**
1896             * Returns <code>true</code> if the team has any users associated with it.
1897             *
1898             * @param pk the primary key of the team to check for associations with users
1899             * @return <code>true</code> if the team has any users associated with it; <code>false</code> otherwise
1900             * @throws SystemException if a system exception occurred
1901             */
1902            public boolean containsUsers(long pk) throws SystemException {
1903                    if (getUsersSize(pk) > 0) {
1904                            return true;
1905                    }
1906                    else {
1907                            return false;
1908                    }
1909            }
1910    
1911            /**
1912             * Adds an association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1913             *
1914             * @param pk the primary key of the team
1915             * @param userPK the primary key of the user
1916             * @throws SystemException if a system exception occurred
1917             */
1918            public void addUser(long pk, long userPK) throws SystemException {
1919                    try {
1920                            addUser.add(pk, userPK);
1921                    }
1922                    catch (Exception e) {
1923                            throw processException(e);
1924                    }
1925                    finally {
1926                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1927                    }
1928            }
1929    
1930            /**
1931             * Adds an association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1932             *
1933             * @param pk the primary key of the team
1934             * @param user the user
1935             * @throws SystemException if a system exception occurred
1936             */
1937            public void addUser(long pk, com.liferay.portal.model.User user)
1938                    throws SystemException {
1939                    try {
1940                            addUser.add(pk, user.getPrimaryKey());
1941                    }
1942                    catch (Exception e) {
1943                            throw processException(e);
1944                    }
1945                    finally {
1946                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1947                    }
1948            }
1949    
1950            /**
1951             * Adds an association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1952             *
1953             * @param pk the primary key of the team
1954             * @param userPKs the primary keys of the users
1955             * @throws SystemException if a system exception occurred
1956             */
1957            public void addUsers(long pk, long[] userPKs) throws SystemException {
1958                    try {
1959                            for (long userPK : userPKs) {
1960                                    addUser.add(pk, userPK);
1961                            }
1962                    }
1963                    catch (Exception e) {
1964                            throw processException(e);
1965                    }
1966                    finally {
1967                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1968                    }
1969            }
1970    
1971            /**
1972             * Adds an association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1973             *
1974             * @param pk the primary key of the team
1975             * @param users the users
1976             * @throws SystemException if a system exception occurred
1977             */
1978            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1979                    throws SystemException {
1980                    try {
1981                            for (com.liferay.portal.model.User user : users) {
1982                                    addUser.add(pk, user.getPrimaryKey());
1983                            }
1984                    }
1985                    catch (Exception e) {
1986                            throw processException(e);
1987                    }
1988                    finally {
1989                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1990                    }
1991            }
1992    
1993            /**
1994             * Clears all associations between the team and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1995             *
1996             * @param pk the primary key of the team to clear the associated users from
1997             * @throws SystemException if a system exception occurred
1998             */
1999            public void clearUsers(long pk) throws SystemException {
2000                    try {
2001                            clearUsers.clear(pk);
2002                    }
2003                    catch (Exception e) {
2004                            throw processException(e);
2005                    }
2006                    finally {
2007                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2008                    }
2009            }
2010    
2011            /**
2012             * Removes the association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2013             *
2014             * @param pk the primary key of the team
2015             * @param userPK the primary key of the user
2016             * @throws SystemException if a system exception occurred
2017             */
2018            public void removeUser(long pk, long userPK) throws SystemException {
2019                    try {
2020                            removeUser.remove(pk, userPK);
2021                    }
2022                    catch (Exception e) {
2023                            throw processException(e);
2024                    }
2025                    finally {
2026                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2027                    }
2028            }
2029    
2030            /**
2031             * Removes the association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2032             *
2033             * @param pk the primary key of the team
2034             * @param user the user
2035             * @throws SystemException if a system exception occurred
2036             */
2037            public void removeUser(long pk, com.liferay.portal.model.User user)
2038                    throws SystemException {
2039                    try {
2040                            removeUser.remove(pk, user.getPrimaryKey());
2041                    }
2042                    catch (Exception e) {
2043                            throw processException(e);
2044                    }
2045                    finally {
2046                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2047                    }
2048            }
2049    
2050            /**
2051             * Removes the association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2052             *
2053             * @param pk the primary key of the team
2054             * @param userPKs the primary keys of the users
2055             * @throws SystemException if a system exception occurred
2056             */
2057            public void removeUsers(long pk, long[] userPKs) throws SystemException {
2058                    try {
2059                            for (long userPK : userPKs) {
2060                                    removeUser.remove(pk, userPK);
2061                            }
2062                    }
2063                    catch (Exception e) {
2064                            throw processException(e);
2065                    }
2066                    finally {
2067                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2068                    }
2069            }
2070    
2071            /**
2072             * Removes the association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2073             *
2074             * @param pk the primary key of the team
2075             * @param users the users
2076             * @throws SystemException if a system exception occurred
2077             */
2078            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2079                    throws SystemException {
2080                    try {
2081                            for (com.liferay.portal.model.User user : users) {
2082                                    removeUser.remove(pk, user.getPrimaryKey());
2083                            }
2084                    }
2085                    catch (Exception e) {
2086                            throw processException(e);
2087                    }
2088                    finally {
2089                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2090                    }
2091            }
2092    
2093            /**
2094             * Sets the users associated with the team, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2095             *
2096             * @param pk the primary key of the team
2097             * @param userPKs the primary keys of the users to be associated with the team
2098             * @throws SystemException if a system exception occurred
2099             */
2100            public void setUsers(long pk, long[] userPKs) throws SystemException {
2101                    try {
2102                            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
2103    
2104                            List<com.liferay.portal.model.User> users = getUsers(pk);
2105    
2106                            for (com.liferay.portal.model.User user : users) {
2107                                    if (!userPKSet.remove(user.getPrimaryKey())) {
2108                                            removeUser.remove(pk, user.getPrimaryKey());
2109                                    }
2110                            }
2111    
2112                            for (Long userPK : userPKSet) {
2113                                    addUser.add(pk, userPK);
2114                            }
2115                    }
2116                    catch (Exception e) {
2117                            throw processException(e);
2118                    }
2119                    finally {
2120                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2121                    }
2122            }
2123    
2124            /**
2125             * Sets the users associated with the team, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2126             *
2127             * @param pk the primary key of the team
2128             * @param users the users to be associated with the team
2129             * @throws SystemException if a system exception occurred
2130             */
2131            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2132                    throws SystemException {
2133                    try {
2134                            long[] userPKs = new long[users.size()];
2135    
2136                            for (int i = 0; i < users.size(); i++) {
2137                                    com.liferay.portal.model.User user = users.get(i);
2138    
2139                                    userPKs[i] = user.getPrimaryKey();
2140                            }
2141    
2142                            setUsers(pk, userPKs);
2143                    }
2144                    catch (Exception e) {
2145                            throw processException(e);
2146                    }
2147                    finally {
2148                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
2149                    }
2150            }
2151    
2152            /**
2153             * Returns all the user groups associated with the team.
2154             *
2155             * @param pk the primary key of the team
2156             * @return the user groups associated with the team
2157             * @throws SystemException if a system exception occurred
2158             */
2159            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk)
2160                    throws SystemException {
2161                    return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2162            }
2163    
2164            /**
2165             * Returns a range of all the user groups associated with the team.
2166             *
2167             * <p>
2168             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2169             * </p>
2170             *
2171             * @param pk the primary key of the team
2172             * @param start the lower bound of the range of teams
2173             * @param end the upper bound of the range of teams (not inclusive)
2174             * @return the range of user groups associated with the team
2175             * @throws SystemException if a system exception occurred
2176             */
2177            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
2178                    int start, int end) throws SystemException {
2179                    return getUserGroups(pk, start, end, null);
2180            }
2181    
2182            public static final FinderPath FINDER_PATH_GET_USERGROUPS = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2183                            TeamModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS,
2184                            com.liferay.portal.model.impl.UserGroupImpl.class,
2185                            TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME, "getUserGroups",
2186                            new String[] {
2187                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2188                                    "com.liferay.portal.kernel.util.OrderByComparator"
2189                            });
2190    
2191            /**
2192             * Returns an ordered range of all the user groups associated with the team.
2193             *
2194             * <p>
2195             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2196             * </p>
2197             *
2198             * @param pk the primary key of the team
2199             * @param start the lower bound of the range of teams
2200             * @param end the upper bound of the range of teams (not inclusive)
2201             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2202             * @return the ordered range of user groups associated with the team
2203             * @throws SystemException if a system exception occurred
2204             */
2205            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
2206                    int start, int end, OrderByComparator orderByComparator)
2207                    throws SystemException {
2208                    Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
2209    
2210                    List<com.liferay.portal.model.UserGroup> list = (List<com.liferay.portal.model.UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS,
2211                                    finderArgs, this);
2212    
2213                    if (list == null) {
2214                            Session session = null;
2215    
2216                            try {
2217                                    session = openSession();
2218    
2219                                    String sql = null;
2220    
2221                                    if (orderByComparator != null) {
2222                                            sql = _SQL_GETUSERGROUPS.concat(ORDER_BY_CLAUSE)
2223                                                                                            .concat(orderByComparator.getOrderBy());
2224                                    }
2225                                    else {
2226                                            sql = _SQL_GETUSERGROUPS.concat(com.liferay.portal.model.impl.UserGroupModelImpl.ORDER_BY_SQL);
2227                                    }
2228    
2229                                    SQLQuery q = session.createSQLQuery(sql);
2230    
2231                                    q.addEntity("UserGroup",
2232                                            com.liferay.portal.model.impl.UserGroupImpl.class);
2233    
2234                                    QueryPos qPos = QueryPos.getInstance(q);
2235    
2236                                    qPos.add(pk);
2237    
2238                                    list = (List<com.liferay.portal.model.UserGroup>)QueryUtil.list(q,
2239                                                    getDialect(), start, end);
2240                            }
2241                            catch (Exception e) {
2242                                    throw processException(e);
2243                            }
2244                            finally {
2245                                    if (list == null) {
2246                                            FinderCacheUtil.removeResult(FINDER_PATH_GET_USERGROUPS,
2247                                                    finderArgs);
2248                                    }
2249                                    else {
2250                                            userGroupPersistence.cacheResult(list);
2251    
2252                                            FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS,
2253                                                    finderArgs, list);
2254                                    }
2255    
2256                                    closeSession(session);
2257                            }
2258                    }
2259    
2260                    return list;
2261            }
2262    
2263            public static final FinderPath FINDER_PATH_GET_USERGROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2264                            TeamModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS, Long.class,
2265                            TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME,
2266                            "getUserGroupsSize", new String[] { Long.class.getName() });
2267    
2268            /**
2269             * Returns the number of user groups associated with the team.
2270             *
2271             * @param pk the primary key of the team
2272             * @return the number of user groups associated with the team
2273             * @throws SystemException if a system exception occurred
2274             */
2275            public int getUserGroupsSize(long pk) throws SystemException {
2276                    Object[] finderArgs = new Object[] { pk };
2277    
2278                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS_SIZE,
2279                                    finderArgs, this);
2280    
2281                    if (count == null) {
2282                            Session session = null;
2283    
2284                            try {
2285                                    session = openSession();
2286    
2287                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERGROUPSSIZE);
2288    
2289                                    q.addScalar(COUNT_COLUMN_NAME,
2290                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
2291    
2292                                    QueryPos qPos = QueryPos.getInstance(q);
2293    
2294                                    qPos.add(pk);
2295    
2296                                    count = (Long)q.uniqueResult();
2297                            }
2298                            catch (Exception e) {
2299                                    throw processException(e);
2300                            }
2301                            finally {
2302                                    if (count == null) {
2303                                            count = Long.valueOf(0);
2304                                    }
2305    
2306                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS_SIZE,
2307                                            finderArgs, count);
2308    
2309                                    closeSession(session);
2310                            }
2311                    }
2312    
2313                    return count.intValue();
2314            }
2315    
2316            public static final FinderPath FINDER_PATH_CONTAINS_USERGROUP = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2317                            TeamModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS, Boolean.class,
2318                            TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME,
2319                            "containsUserGroup",
2320                            new String[] { Long.class.getName(), Long.class.getName() });
2321    
2322            /**
2323             * Returns <code>true</code> if the user group is associated with the team.
2324             *
2325             * @param pk the primary key of the team
2326             * @param userGroupPK the primary key of the user group
2327             * @return <code>true</code> if the user group is associated with the team; <code>false</code> otherwise
2328             * @throws SystemException if a system exception occurred
2329             */
2330            public boolean containsUserGroup(long pk, long userGroupPK)
2331                    throws SystemException {
2332                    Object[] finderArgs = new Object[] { pk, userGroupPK };
2333    
2334                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USERGROUP,
2335                                    finderArgs, this);
2336    
2337                    if (value == null) {
2338                            try {
2339                                    value = Boolean.valueOf(containsUserGroup.contains(pk,
2340                                                            userGroupPK));
2341                            }
2342                            catch (Exception e) {
2343                                    throw processException(e);
2344                            }
2345                            finally {
2346                                    if (value == null) {
2347                                            value = Boolean.FALSE;
2348                                    }
2349    
2350                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USERGROUP,
2351                                            finderArgs, value);
2352                            }
2353                    }
2354    
2355                    return value.booleanValue();
2356            }
2357    
2358            /**
2359             * Returns <code>true</code> if the team has any user groups associated with it.
2360             *
2361             * @param pk the primary key of the team to check for associations with user groups
2362             * @return <code>true</code> if the team has any user groups associated with it; <code>false</code> otherwise
2363             * @throws SystemException if a system exception occurred
2364             */
2365            public boolean containsUserGroups(long pk) throws SystemException {
2366                    if (getUserGroupsSize(pk) > 0) {
2367                            return true;
2368                    }
2369                    else {
2370                            return false;
2371                    }
2372            }
2373    
2374            /**
2375             * Adds an association between the team and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2376             *
2377             * @param pk the primary key of the team
2378             * @param userGroupPK the primary key of the user group
2379             * @throws SystemException if a system exception occurred
2380             */
2381            public void addUserGroup(long pk, long userGroupPK)
2382                    throws SystemException {
2383                    try {
2384                            addUserGroup.add(pk, userGroupPK);
2385                    }
2386                    catch (Exception e) {
2387                            throw processException(e);
2388                    }
2389                    finally {
2390                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2391                    }
2392            }
2393    
2394            /**
2395             * Adds an association between the team and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2396             *
2397             * @param pk the primary key of the team
2398             * @param userGroup the user group
2399             * @throws SystemException if a system exception occurred
2400             */
2401            public void addUserGroup(long pk,
2402                    com.liferay.portal.model.UserGroup userGroup) throws SystemException {
2403                    try {
2404                            addUserGroup.add(pk, userGroup.getPrimaryKey());
2405                    }
2406                    catch (Exception e) {
2407                            throw processException(e);
2408                    }
2409                    finally {
2410                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2411                    }
2412            }
2413    
2414            /**
2415             * Adds an association between the team and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2416             *
2417             * @param pk the primary key of the team
2418             * @param userGroupPKs the primary keys of the user groups
2419             * @throws SystemException if a system exception occurred
2420             */
2421            public void addUserGroups(long pk, long[] userGroupPKs)
2422                    throws SystemException {
2423                    try {
2424                            for (long userGroupPK : userGroupPKs) {
2425                                    addUserGroup.add(pk, userGroupPK);
2426                            }
2427                    }
2428                    catch (Exception e) {
2429                            throw processException(e);
2430                    }
2431                    finally {
2432                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2433                    }
2434            }
2435    
2436            /**
2437             * Adds an association between the team and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2438             *
2439             * @param pk the primary key of the team
2440             * @param userGroups the user groups
2441             * @throws SystemException if a system exception occurred
2442             */
2443            public void addUserGroups(long pk,
2444                    List<com.liferay.portal.model.UserGroup> userGroups)
2445                    throws SystemException {
2446                    try {
2447                            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
2448                                    addUserGroup.add(pk, userGroup.getPrimaryKey());
2449                            }
2450                    }
2451                    catch (Exception e) {
2452                            throw processException(e);
2453                    }
2454                    finally {
2455                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2456                    }
2457            }
2458    
2459            /**
2460             * Clears all associations between the team and its user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2461             *
2462             * @param pk the primary key of the team to clear the associated user groups from
2463             * @throws SystemException if a system exception occurred
2464             */
2465            public void clearUserGroups(long pk) throws SystemException {
2466                    try {
2467                            clearUserGroups.clear(pk);
2468                    }
2469                    catch (Exception e) {
2470                            throw processException(e);
2471                    }
2472                    finally {
2473                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2474                    }
2475            }
2476    
2477            /**
2478             * Removes the association between the team and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2479             *
2480             * @param pk the primary key of the team
2481             * @param userGroupPK the primary key of the user group
2482             * @throws SystemException if a system exception occurred
2483             */
2484            public void removeUserGroup(long pk, long userGroupPK)
2485                    throws SystemException {
2486                    try {
2487                            removeUserGroup.remove(pk, userGroupPK);
2488                    }
2489                    catch (Exception e) {
2490                            throw processException(e);
2491                    }
2492                    finally {
2493                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2494                    }
2495            }
2496    
2497            /**
2498             * Removes the association between the team and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2499             *
2500             * @param pk the primary key of the team
2501             * @param userGroup the user group
2502             * @throws SystemException if a system exception occurred
2503             */
2504            public void removeUserGroup(long pk,
2505                    com.liferay.portal.model.UserGroup userGroup) throws SystemException {
2506                    try {
2507                            removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2508                    }
2509                    catch (Exception e) {
2510                            throw processException(e);
2511                    }
2512                    finally {
2513                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2514                    }
2515            }
2516    
2517            /**
2518             * Removes the association between the team and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2519             *
2520             * @param pk the primary key of the team
2521             * @param userGroupPKs the primary keys of the user groups
2522             * @throws SystemException if a system exception occurred
2523             */
2524            public void removeUserGroups(long pk, long[] userGroupPKs)
2525                    throws SystemException {
2526                    try {
2527                            for (long userGroupPK : userGroupPKs) {
2528                                    removeUserGroup.remove(pk, userGroupPK);
2529                            }
2530                    }
2531                    catch (Exception e) {
2532                            throw processException(e);
2533                    }
2534                    finally {
2535                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2536                    }
2537            }
2538    
2539            /**
2540             * Removes the association between the team and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2541             *
2542             * @param pk the primary key of the team
2543             * @param userGroups the user groups
2544             * @throws SystemException if a system exception occurred
2545             */
2546            public void removeUserGroups(long pk,
2547                    List<com.liferay.portal.model.UserGroup> userGroups)
2548                    throws SystemException {
2549                    try {
2550                            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
2551                                    removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2552                            }
2553                    }
2554                    catch (Exception e) {
2555                            throw processException(e);
2556                    }
2557                    finally {
2558                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2559                    }
2560            }
2561    
2562            /**
2563             * Sets the user groups associated with the team, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2564             *
2565             * @param pk the primary key of the team
2566             * @param userGroupPKs the primary keys of the user groups to be associated with the team
2567             * @throws SystemException if a system exception occurred
2568             */
2569            public void setUserGroups(long pk, long[] userGroupPKs)
2570                    throws SystemException {
2571                    try {
2572                            Set<Long> userGroupPKSet = SetUtil.fromArray(userGroupPKs);
2573    
2574                            List<com.liferay.portal.model.UserGroup> userGroups = getUserGroups(pk);
2575    
2576                            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
2577                                    if (!userGroupPKSet.remove(userGroup.getPrimaryKey())) {
2578                                            removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2579                                    }
2580                            }
2581    
2582                            for (Long userGroupPK : userGroupPKSet) {
2583                                    addUserGroup.add(pk, userGroupPK);
2584                            }
2585                    }
2586                    catch (Exception e) {
2587                            throw processException(e);
2588                    }
2589                    finally {
2590                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2591                    }
2592            }
2593    
2594            /**
2595             * Sets the user groups associated with the team, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2596             *
2597             * @param pk the primary key of the team
2598             * @param userGroups the user groups to be associated with the team
2599             * @throws SystemException if a system exception occurred
2600             */
2601            public void setUserGroups(long pk,
2602                    List<com.liferay.portal.model.UserGroup> userGroups)
2603                    throws SystemException {
2604                    try {
2605                            long[] userGroupPKs = new long[userGroups.size()];
2606    
2607                            for (int i = 0; i < userGroups.size(); i++) {
2608                                    com.liferay.portal.model.UserGroup userGroup = userGroups.get(i);
2609    
2610                                    userGroupPKs[i] = userGroup.getPrimaryKey();
2611                            }
2612    
2613                            setUserGroups(pk, userGroupPKs);
2614                    }
2615                    catch (Exception e) {
2616                            throw processException(e);
2617                    }
2618                    finally {
2619                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
2620                    }
2621            }
2622    
2623            /**
2624             * Initializes the team persistence.
2625             */
2626            public void afterPropertiesSet() {
2627                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2628                                            com.liferay.portal.util.PropsUtil.get(
2629                                                    "value.object.listener.com.liferay.portal.model.Team")));
2630    
2631                    if (listenerClassNames.length > 0) {
2632                            try {
2633                                    List<ModelListener<Team>> listenersList = new ArrayList<ModelListener<Team>>();
2634    
2635                                    for (String listenerClassName : listenerClassNames) {
2636                                            listenersList.add((ModelListener<Team>)InstanceFactory.newInstance(
2637                                                            listenerClassName));
2638                                    }
2639    
2640                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2641                            }
2642                            catch (Exception e) {
2643                                    _log.error(e);
2644                            }
2645                    }
2646    
2647                    containsUser = new ContainsUser(this);
2648    
2649                    addUser = new AddUser(this);
2650                    clearUsers = new ClearUsers(this);
2651                    removeUser = new RemoveUser(this);
2652    
2653                    containsUserGroup = new ContainsUserGroup(this);
2654    
2655                    addUserGroup = new AddUserGroup(this);
2656                    clearUserGroups = new ClearUserGroups(this);
2657                    removeUserGroup = new RemoveUserGroup(this);
2658            }
2659    
2660            public void destroy() {
2661                    EntityCacheUtil.removeCache(TeamImpl.class.getName());
2662                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2663                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2664            }
2665    
2666            @BeanReference(type = AccountPersistence.class)
2667            protected AccountPersistence accountPersistence;
2668            @BeanReference(type = AddressPersistence.class)
2669            protected AddressPersistence addressPersistence;
2670            @BeanReference(type = BrowserTrackerPersistence.class)
2671            protected BrowserTrackerPersistence browserTrackerPersistence;
2672            @BeanReference(type = ClassNamePersistence.class)
2673            protected ClassNamePersistence classNamePersistence;
2674            @BeanReference(type = ClusterGroupPersistence.class)
2675            protected ClusterGroupPersistence clusterGroupPersistence;
2676            @BeanReference(type = CompanyPersistence.class)
2677            protected CompanyPersistence companyPersistence;
2678            @BeanReference(type = ContactPersistence.class)
2679            protected ContactPersistence contactPersistence;
2680            @BeanReference(type = CountryPersistence.class)
2681            protected CountryPersistence countryPersistence;
2682            @BeanReference(type = EmailAddressPersistence.class)
2683            protected EmailAddressPersistence emailAddressPersistence;
2684            @BeanReference(type = GroupPersistence.class)
2685            protected GroupPersistence groupPersistence;
2686            @BeanReference(type = ImagePersistence.class)
2687            protected ImagePersistence imagePersistence;
2688            @BeanReference(type = LayoutPersistence.class)
2689            protected LayoutPersistence layoutPersistence;
2690            @BeanReference(type = LayoutBranchPersistence.class)
2691            protected LayoutBranchPersistence layoutBranchPersistence;
2692            @BeanReference(type = LayoutPrototypePersistence.class)
2693            protected LayoutPrototypePersistence layoutPrototypePersistence;
2694            @BeanReference(type = LayoutRevisionPersistence.class)
2695            protected LayoutRevisionPersistence layoutRevisionPersistence;
2696            @BeanReference(type = LayoutSetPersistence.class)
2697            protected LayoutSetPersistence layoutSetPersistence;
2698            @BeanReference(type = LayoutSetBranchPersistence.class)
2699            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2700            @BeanReference(type = LayoutSetPrototypePersistence.class)
2701            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2702            @BeanReference(type = ListTypePersistence.class)
2703            protected ListTypePersistence listTypePersistence;
2704            @BeanReference(type = LockPersistence.class)
2705            protected LockPersistence lockPersistence;
2706            @BeanReference(type = MembershipRequestPersistence.class)
2707            protected MembershipRequestPersistence membershipRequestPersistence;
2708            @BeanReference(type = OrganizationPersistence.class)
2709            protected OrganizationPersistence organizationPersistence;
2710            @BeanReference(type = OrgGroupPermissionPersistence.class)
2711            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2712            @BeanReference(type = OrgGroupRolePersistence.class)
2713            protected OrgGroupRolePersistence orgGroupRolePersistence;
2714            @BeanReference(type = OrgLaborPersistence.class)
2715            protected OrgLaborPersistence orgLaborPersistence;
2716            @BeanReference(type = PasswordPolicyPersistence.class)
2717            protected PasswordPolicyPersistence passwordPolicyPersistence;
2718            @BeanReference(type = PasswordPolicyRelPersistence.class)
2719            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2720            @BeanReference(type = PasswordTrackerPersistence.class)
2721            protected PasswordTrackerPersistence passwordTrackerPersistence;
2722            @BeanReference(type = PermissionPersistence.class)
2723            protected PermissionPersistence permissionPersistence;
2724            @BeanReference(type = PhonePersistence.class)
2725            protected PhonePersistence phonePersistence;
2726            @BeanReference(type = PluginSettingPersistence.class)
2727            protected PluginSettingPersistence pluginSettingPersistence;
2728            @BeanReference(type = PortalPreferencesPersistence.class)
2729            protected PortalPreferencesPersistence portalPreferencesPersistence;
2730            @BeanReference(type = PortletPersistence.class)
2731            protected PortletPersistence portletPersistence;
2732            @BeanReference(type = PortletItemPersistence.class)
2733            protected PortletItemPersistence portletItemPersistence;
2734            @BeanReference(type = PortletPreferencesPersistence.class)
2735            protected PortletPreferencesPersistence portletPreferencesPersistence;
2736            @BeanReference(type = RegionPersistence.class)
2737            protected RegionPersistence regionPersistence;
2738            @BeanReference(type = ReleasePersistence.class)
2739            protected ReleasePersistence releasePersistence;
2740            @BeanReference(type = RepositoryPersistence.class)
2741            protected RepositoryPersistence repositoryPersistence;
2742            @BeanReference(type = RepositoryEntryPersistence.class)
2743            protected RepositoryEntryPersistence repositoryEntryPersistence;
2744            @BeanReference(type = ResourcePersistence.class)
2745            protected ResourcePersistence resourcePersistence;
2746            @BeanReference(type = ResourceActionPersistence.class)
2747            protected ResourceActionPersistence resourceActionPersistence;
2748            @BeanReference(type = ResourceBlockPersistence.class)
2749            protected ResourceBlockPersistence resourceBlockPersistence;
2750            @BeanReference(type = ResourceBlockPermissionPersistence.class)
2751            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2752            @BeanReference(type = ResourceCodePersistence.class)
2753            protected ResourceCodePersistence resourceCodePersistence;
2754            @BeanReference(type = ResourcePermissionPersistence.class)
2755            protected ResourcePermissionPersistence resourcePermissionPersistence;
2756            @BeanReference(type = ResourceTypePermissionPersistence.class)
2757            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2758            @BeanReference(type = RolePersistence.class)
2759            protected RolePersistence rolePersistence;
2760            @BeanReference(type = ServiceComponentPersistence.class)
2761            protected ServiceComponentPersistence serviceComponentPersistence;
2762            @BeanReference(type = ShardPersistence.class)
2763            protected ShardPersistence shardPersistence;
2764            @BeanReference(type = SubscriptionPersistence.class)
2765            protected SubscriptionPersistence subscriptionPersistence;
2766            @BeanReference(type = TeamPersistence.class)
2767            protected TeamPersistence teamPersistence;
2768            @BeanReference(type = TicketPersistence.class)
2769            protected TicketPersistence ticketPersistence;
2770            @BeanReference(type = UserPersistence.class)
2771            protected UserPersistence userPersistence;
2772            @BeanReference(type = UserGroupPersistence.class)
2773            protected UserGroupPersistence userGroupPersistence;
2774            @BeanReference(type = UserGroupGroupRolePersistence.class)
2775            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2776            @BeanReference(type = UserGroupRolePersistence.class)
2777            protected UserGroupRolePersistence userGroupRolePersistence;
2778            @BeanReference(type = UserIdMapperPersistence.class)
2779            protected UserIdMapperPersistence userIdMapperPersistence;
2780            @BeanReference(type = UserNotificationEventPersistence.class)
2781            protected UserNotificationEventPersistence userNotificationEventPersistence;
2782            @BeanReference(type = UserTrackerPersistence.class)
2783            protected UserTrackerPersistence userTrackerPersistence;
2784            @BeanReference(type = UserTrackerPathPersistence.class)
2785            protected UserTrackerPathPersistence userTrackerPathPersistence;
2786            @BeanReference(type = VirtualHostPersistence.class)
2787            protected VirtualHostPersistence virtualHostPersistence;
2788            @BeanReference(type = WebDAVPropsPersistence.class)
2789            protected WebDAVPropsPersistence webDAVPropsPersistence;
2790            @BeanReference(type = WebsitePersistence.class)
2791            protected WebsitePersistence websitePersistence;
2792            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2793            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2794            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2795            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2796            protected ContainsUser containsUser;
2797            protected AddUser addUser;
2798            protected ClearUsers clearUsers;
2799            protected RemoveUser removeUser;
2800            protected ContainsUserGroup containsUserGroup;
2801            protected AddUserGroup addUserGroup;
2802            protected ClearUserGroups clearUserGroups;
2803            protected RemoveUserGroup removeUserGroup;
2804    
2805            protected class ContainsUser {
2806                    protected ContainsUser(TeamPersistenceImpl persistenceImpl) {
2807                            super();
2808    
2809                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2810                                            _SQL_CONTAINSUSER,
2811                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2812                                            RowMapper.COUNT);
2813                    }
2814    
2815                    protected boolean contains(long teamId, long userId) {
2816                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2817                                                    new Long(teamId), new Long(userId)
2818                                            });
2819    
2820                            if (results.size() > 0) {
2821                                    Integer count = results.get(0);
2822    
2823                                    if (count.intValue() > 0) {
2824                                            return true;
2825                                    }
2826                            }
2827    
2828                            return false;
2829                    }
2830    
2831                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2832            }
2833    
2834            protected class AddUser {
2835                    protected AddUser(TeamPersistenceImpl persistenceImpl) {
2836                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2837                                            "INSERT INTO Users_Teams (teamId, userId) VALUES (?, ?)",
2838                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2839                            _persistenceImpl = persistenceImpl;
2840                    }
2841    
2842                    protected void add(long teamId, long userId) throws SystemException {
2843                            if (!_persistenceImpl.containsUser.contains(teamId, userId)) {
2844                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2845    
2846                                    for (ModelListener<Team> listener : listeners) {
2847                                            listener.onBeforeAddAssociation(teamId,
2848                                                    com.liferay.portal.model.User.class.getName(), userId);
2849                                    }
2850    
2851                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2852                                            listener.onBeforeAddAssociation(userId,
2853                                                    Team.class.getName(), teamId);
2854                                    }
2855    
2856                                    _sqlUpdate.update(new Object[] {
2857                                                    new Long(teamId), new Long(userId)
2858                                            });
2859    
2860                                    for (ModelListener<Team> listener : listeners) {
2861                                            listener.onAfterAddAssociation(teamId,
2862                                                    com.liferay.portal.model.User.class.getName(), userId);
2863                                    }
2864    
2865                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2866                                            listener.onAfterAddAssociation(userId,
2867                                                    Team.class.getName(), teamId);
2868                                    }
2869                            }
2870                    }
2871    
2872                    private SqlUpdate _sqlUpdate;
2873                    private TeamPersistenceImpl _persistenceImpl;
2874            }
2875    
2876            protected class ClearUsers {
2877                    protected ClearUsers(TeamPersistenceImpl persistenceImpl) {
2878                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2879                                            "DELETE FROM Users_Teams WHERE teamId = ?",
2880                                            new int[] { java.sql.Types.BIGINT });
2881                    }
2882    
2883                    protected void clear(long teamId) throws SystemException {
2884                            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2885    
2886                            List<com.liferay.portal.model.User> users = null;
2887    
2888                            if ((listeners.length > 0) || (userListeners.length > 0)) {
2889                                    users = getUsers(teamId);
2890    
2891                                    for (com.liferay.portal.model.User user : users) {
2892                                            for (ModelListener<Team> listener : listeners) {
2893                                                    listener.onBeforeRemoveAssociation(teamId,
2894                                                            com.liferay.portal.model.User.class.getName(),
2895                                                            user.getPrimaryKey());
2896                                            }
2897    
2898                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2899                                                    listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2900                                                            Team.class.getName(), teamId);
2901                                            }
2902                                    }
2903                            }
2904    
2905                            _sqlUpdate.update(new Object[] { new Long(teamId) });
2906    
2907                            if ((listeners.length > 0) || (userListeners.length > 0)) {
2908                                    for (com.liferay.portal.model.User user : users) {
2909                                            for (ModelListener<Team> listener : listeners) {
2910                                                    listener.onAfterRemoveAssociation(teamId,
2911                                                            com.liferay.portal.model.User.class.getName(),
2912                                                            user.getPrimaryKey());
2913                                            }
2914    
2915                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2916                                                    listener.onAfterRemoveAssociation(user.getPrimaryKey(),
2917                                                            Team.class.getName(), teamId);
2918                                            }
2919                                    }
2920                            }
2921                    }
2922    
2923                    private SqlUpdate _sqlUpdate;
2924            }
2925    
2926            protected class RemoveUser {
2927                    protected RemoveUser(TeamPersistenceImpl persistenceImpl) {
2928                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2929                                            "DELETE FROM Users_Teams WHERE teamId = ? AND userId = ?",
2930                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2931                            _persistenceImpl = persistenceImpl;
2932                    }
2933    
2934                    protected void remove(long teamId, long userId)
2935                            throws SystemException {
2936                            if (_persistenceImpl.containsUser.contains(teamId, userId)) {
2937                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2938    
2939                                    for (ModelListener<Team> listener : listeners) {
2940                                            listener.onBeforeRemoveAssociation(teamId,
2941                                                    com.liferay.portal.model.User.class.getName(), userId);
2942                                    }
2943    
2944                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2945                                            listener.onBeforeRemoveAssociation(userId,
2946                                                    Team.class.getName(), teamId);
2947                                    }
2948    
2949                                    _sqlUpdate.update(new Object[] {
2950                                                    new Long(teamId), new Long(userId)
2951                                            });
2952    
2953                                    for (ModelListener<Team> listener : listeners) {
2954                                            listener.onAfterRemoveAssociation(teamId,
2955                                                    com.liferay.portal.model.User.class.getName(), userId);
2956                                    }
2957    
2958                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2959                                            listener.onAfterRemoveAssociation(userId,
2960                                                    Team.class.getName(), teamId);
2961                                    }
2962                            }
2963                    }
2964    
2965                    private SqlUpdate _sqlUpdate;
2966                    private TeamPersistenceImpl _persistenceImpl;
2967            }
2968    
2969            protected class ContainsUserGroup {
2970                    protected ContainsUserGroup(TeamPersistenceImpl persistenceImpl) {
2971                            super();
2972    
2973                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2974                                            _SQL_CONTAINSUSERGROUP,
2975                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2976                                            RowMapper.COUNT);
2977                    }
2978    
2979                    protected boolean contains(long teamId, long userGroupId) {
2980                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2981                                                    new Long(teamId), new Long(userGroupId)
2982                                            });
2983    
2984                            if (results.size() > 0) {
2985                                    Integer count = results.get(0);
2986    
2987                                    if (count.intValue() > 0) {
2988                                            return true;
2989                                    }
2990                            }
2991    
2992                            return false;
2993                    }
2994    
2995                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2996            }
2997    
2998            protected class AddUserGroup {
2999                    protected AddUserGroup(TeamPersistenceImpl persistenceImpl) {
3000                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3001                                            "INSERT INTO UserGroups_Teams (teamId, userGroupId) VALUES (?, ?)",
3002                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3003                            _persistenceImpl = persistenceImpl;
3004                    }
3005    
3006                    protected void add(long teamId, long userGroupId)
3007                            throws SystemException {
3008                            if (!_persistenceImpl.containsUserGroup.contains(teamId, userGroupId)) {
3009                                    ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
3010                                            userGroupPersistence.getListeners();
3011    
3012                                    for (ModelListener<Team> listener : listeners) {
3013                                            listener.onBeforeAddAssociation(teamId,
3014                                                    com.liferay.portal.model.UserGroup.class.getName(),
3015                                                    userGroupId);
3016                                    }
3017    
3018                                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3019                                            listener.onBeforeAddAssociation(userGroupId,
3020                                                    Team.class.getName(), teamId);
3021                                    }
3022    
3023                                    _sqlUpdate.update(new Object[] {
3024                                                    new Long(teamId), new Long(userGroupId)
3025                                            });
3026    
3027                                    for (ModelListener<Team> listener : listeners) {
3028                                            listener.onAfterAddAssociation(teamId,
3029                                                    com.liferay.portal.model.UserGroup.class.getName(),
3030                                                    userGroupId);
3031                                    }
3032    
3033                                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3034                                            listener.onAfterAddAssociation(userGroupId,
3035                                                    Team.class.getName(), teamId);
3036                                    }
3037                            }
3038                    }
3039    
3040                    private SqlUpdate _sqlUpdate;
3041                    private TeamPersistenceImpl _persistenceImpl;
3042            }
3043    
3044            protected class ClearUserGroups {
3045                    protected ClearUserGroups(TeamPersistenceImpl persistenceImpl) {
3046                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3047                                            "DELETE FROM UserGroups_Teams WHERE teamId = ?",
3048                                            new int[] { java.sql.Types.BIGINT });
3049                    }
3050    
3051                    protected void clear(long teamId) throws SystemException {
3052                            ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
3053                                    userGroupPersistence.getListeners();
3054    
3055                            List<com.liferay.portal.model.UserGroup> userGroups = null;
3056    
3057                            if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
3058                                    userGroups = getUserGroups(teamId);
3059    
3060                                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
3061                                            for (ModelListener<Team> listener : listeners) {
3062                                                    listener.onBeforeRemoveAssociation(teamId,
3063                                                            com.liferay.portal.model.UserGroup.class.getName(),
3064                                                            userGroup.getPrimaryKey());
3065                                            }
3066    
3067                                            for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3068                                                    listener.onBeforeRemoveAssociation(userGroup.getPrimaryKey(),
3069                                                            Team.class.getName(), teamId);
3070                                            }
3071                                    }
3072                            }
3073    
3074                            _sqlUpdate.update(new Object[] { new Long(teamId) });
3075    
3076                            if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
3077                                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
3078                                            for (ModelListener<Team> listener : listeners) {
3079                                                    listener.onAfterRemoveAssociation(teamId,
3080                                                            com.liferay.portal.model.UserGroup.class.getName(),
3081                                                            userGroup.getPrimaryKey());
3082                                            }
3083    
3084                                            for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3085                                                    listener.onAfterRemoveAssociation(userGroup.getPrimaryKey(),
3086                                                            Team.class.getName(), teamId);
3087                                            }
3088                                    }
3089                            }
3090                    }
3091    
3092                    private SqlUpdate _sqlUpdate;
3093            }
3094    
3095            protected class RemoveUserGroup {
3096                    protected RemoveUserGroup(TeamPersistenceImpl persistenceImpl) {
3097                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3098                                            "DELETE FROM UserGroups_Teams WHERE teamId = ? AND userGroupId = ?",
3099                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3100                            _persistenceImpl = persistenceImpl;
3101                    }
3102    
3103                    protected void remove(long teamId, long userGroupId)
3104                            throws SystemException {
3105                            if (_persistenceImpl.containsUserGroup.contains(teamId, userGroupId)) {
3106                                    ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
3107                                            userGroupPersistence.getListeners();
3108    
3109                                    for (ModelListener<Team> listener : listeners) {
3110                                            listener.onBeforeRemoveAssociation(teamId,
3111                                                    com.liferay.portal.model.UserGroup.class.getName(),
3112                                                    userGroupId);
3113                                    }
3114    
3115                                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3116                                            listener.onBeforeRemoveAssociation(userGroupId,
3117                                                    Team.class.getName(), teamId);
3118                                    }
3119    
3120                                    _sqlUpdate.update(new Object[] {
3121                                                    new Long(teamId), new Long(userGroupId)
3122                                            });
3123    
3124                                    for (ModelListener<Team> listener : listeners) {
3125                                            listener.onAfterRemoveAssociation(teamId,
3126                                                    com.liferay.portal.model.UserGroup.class.getName(),
3127                                                    userGroupId);
3128                                    }
3129    
3130                                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
3131                                            listener.onAfterRemoveAssociation(userGroupId,
3132                                                    Team.class.getName(), teamId);
3133                                    }
3134                            }
3135                    }
3136    
3137                    private SqlUpdate _sqlUpdate;
3138                    private TeamPersistenceImpl _persistenceImpl;
3139            }
3140    
3141            private static final String _SQL_SELECT_TEAM = "SELECT team FROM Team team";
3142            private static final String _SQL_SELECT_TEAM_WHERE = "SELECT team FROM Team team WHERE ";
3143            private static final String _SQL_COUNT_TEAM = "SELECT COUNT(team) FROM Team team";
3144            private static final String _SQL_COUNT_TEAM_WHERE = "SELECT COUNT(team) FROM Team team WHERE ";
3145            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Teams ON (Users_Teams.userId = User_.userId) WHERE (Users_Teams.teamId = ?)";
3146            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Teams WHERE teamId = ?";
3147            private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Teams WHERE teamId = ? AND userId = ?";
3148            private static final String _SQL_GETUSERGROUPS = "SELECT {UserGroup.*} FROM UserGroup INNER JOIN UserGroups_Teams ON (UserGroups_Teams.userGroupId = UserGroup.userGroupId) WHERE (UserGroups_Teams.teamId = ?)";
3149            private static final String _SQL_GETUSERGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM UserGroups_Teams WHERE teamId = ?";
3150            private static final String _SQL_CONTAINSUSERGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM UserGroups_Teams WHERE teamId = ? AND userGroupId = ?";
3151            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "team.groupId = ?";
3152            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "team.groupId = ? AND ";
3153            private static final String _FINDER_COLUMN_G_N_NAME_1 = "team.name IS NULL";
3154            private static final String _FINDER_COLUMN_G_N_NAME_2 = "team.name = ?";
3155            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(team.name IS NULL OR team.name = ?)";
3156            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "team.teamId";
3157            private static final String _FILTER_SQL_SELECT_TEAM_WHERE = "SELECT DISTINCT {team.*} FROM Team team WHERE ";
3158            private static final String _FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_1 =
3159                    "SELECT {Team.*} FROM (SELECT DISTINCT team.teamId FROM Team team WHERE ";
3160            private static final String _FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_2 =
3161                    ") TEMP_TABLE INNER JOIN Team ON TEMP_TABLE.teamId = Team.teamId";
3162            private static final String _FILTER_SQL_COUNT_TEAM_WHERE = "SELECT COUNT(DISTINCT team.teamId) AS COUNT_VALUE FROM Team team WHERE ";
3163            private static final String _FILTER_ENTITY_ALIAS = "team";
3164            private static final String _FILTER_ENTITY_TABLE = "Team";
3165            private static final String _ORDER_BY_ENTITY_ALIAS = "team.";
3166            private static final String _ORDER_BY_ENTITY_TABLE = "Team.";
3167            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Team exists with the primary key ";
3168            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Team exists with the key {";
3169            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3170            private static Log _log = LogFactoryUtil.getLog(TeamPersistenceImpl.class);
3171            private static Team _nullTeam = new TeamImpl() {
3172                            @Override
3173                            public Object clone() {
3174                                    return this;
3175                            }
3176    
3177                            @Override
3178                            public CacheModel<Team> toCacheModel() {
3179                                    return _nullTeamCacheModel;
3180                            }
3181                    };
3182    
3183            private static CacheModel<Team> _nullTeamCacheModel = new CacheModel<Team>() {
3184                            public Team toEntityModel() {
3185                                    return _nullTeam;
3186                            }
3187                    };
3188    }