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