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