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