001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchTeamException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.SQLQuery;
033    import com.liferay.portal.kernel.dao.orm.Session;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.util.GetterUtil;
038    import com.liferay.portal.kernel.util.InstanceFactory;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.SetUtil;
041    import com.liferay.portal.kernel.util.StringBundler;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.model.Team;
047    import com.liferay.portal.model.impl.TeamImpl;
048    import com.liferay.portal.model.impl.TeamModelImpl;
049    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
050    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.List;
057    import java.util.Set;
058    
059    /**
060     * The persistence implementation for the team service.
061     *
062     * <p>
063     * 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.
064     * </p>
065     *
066     * <p>
067     * Caching information and settings can be found in <code>portal.properties</code>
068     * </p>
069     *
070     * @author Brian Wing Shun Chan
071     * @see TeamPersistence
072     * @see TeamUtil
073     * @generated
074     */
075    public class TeamPersistenceImpl extends BasePersistenceImpl<Team>
076            implements TeamPersistence {
077            public static final String FINDER_CLASS_NAME_ENTITY = TeamImpl.class.getName();
078            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
079                    ".List";
080            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
081                            TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082                            "findByGroupId",
083                            new String[] {
084                                    Long.class.getName(),
085                                    
086                            "java.lang.Integer", "java.lang.Integer",
087                                    "com.liferay.portal.kernel.util.OrderByComparator"
088                            });
089            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
090                            TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
091                            "countByGroupId", new String[] { Long.class.getName() });
092            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
093                            TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
094                            "fetchByG_N",
095                            new String[] { Long.class.getName(), String.class.getName() });
096            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
097                            TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
098                            "countByG_N",
099                            new String[] { Long.class.getName(), String.class.getName() });
100            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
101                            TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102                            "findAll", new String[0]);
103            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
104                            TeamModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105                            "countAll", new String[0]);
106    
107            /**
108             * Caches the team in the entity cache if it is enabled.
109             *
110             * @param team the team to cache
111             */
112            public void cacheResult(Team team) {
113                    EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
114                            TeamImpl.class, team.getPrimaryKey(), team);
115    
116                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
117                            new Object[] { new Long(team.getGroupId()), team.getName() }, team);
118            }
119    
120            /**
121             * Caches the teams in the entity cache if it is enabled.
122             *
123             * @param teams the teams to cache
124             */
125            public void cacheResult(List<Team> teams) {
126                    for (Team team : teams) {
127                            if (EntityCacheUtil.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
128                                                    TeamImpl.class, team.getPrimaryKey(), this) == null) {
129                                    cacheResult(team);
130                            }
131                    }
132            }
133    
134            /**
135             * Clears the cache for all teams.
136             *
137             * <p>
138             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
139             * </p>
140             */
141            public void clearCache() {
142                    CacheRegistryUtil.clear(TeamImpl.class.getName());
143                    EntityCacheUtil.clearCache(TeamImpl.class.getName());
144                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
145                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
146            }
147    
148            /**
149             * Clears the cache for the team.
150             *
151             * <p>
152             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
153             * </p>
154             */
155            public void clearCache(Team team) {
156                    EntityCacheUtil.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
157                            TeamImpl.class, team.getPrimaryKey());
158    
159                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
160                            new Object[] { new Long(team.getGroupId()), team.getName() });
161            }
162    
163            /**
164             * Creates a new team with the primary key. Does not add the team to the database.
165             *
166             * @param teamId the primary key for the new team
167             * @return the new team
168             */
169            public Team create(long teamId) {
170                    Team team = new TeamImpl();
171    
172                    team.setNew(true);
173                    team.setPrimaryKey(teamId);
174    
175                    return team;
176            }
177    
178            /**
179             * Removes the team with the primary key from the database. Also notifies the appropriate model listeners.
180             *
181             * @param primaryKey the primary key of the team to remove
182             * @return the team that was removed
183             * @throws com.liferay.portal.NoSuchModelException if a team with the primary key could not be found
184             * @throws SystemException if a system exception occurred
185             */
186            public Team remove(Serializable primaryKey)
187                    throws NoSuchModelException, SystemException {
188                    return remove(((Long)primaryKey).longValue());
189            }
190    
191            /**
192             * Removes the team with the primary key from the database. Also notifies the appropriate model listeners.
193             *
194             * @param teamId the primary key of the team to remove
195             * @return the team that was removed
196             * @throws com.liferay.portal.NoSuchTeamException if a team with the primary key could not be found
197             * @throws SystemException if a system exception occurred
198             */
199            public Team remove(long teamId) throws NoSuchTeamException, SystemException {
200                    Session session = null;
201    
202                    try {
203                            session = openSession();
204    
205                            Team team = (Team)session.get(TeamImpl.class, new Long(teamId));
206    
207                            if (team == null) {
208                                    if (_log.isWarnEnabled()) {
209                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + teamId);
210                                    }
211    
212                                    throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
213                                            teamId);
214                            }
215    
216                            return remove(team);
217                    }
218                    catch (NoSuchTeamException nsee) {
219                            throw nsee;
220                    }
221                    catch (Exception e) {
222                            throw processException(e);
223                    }
224                    finally {
225                            closeSession(session);
226                    }
227            }
228    
229            protected Team removeImpl(Team team) throws SystemException {
230                    team = toUnwrappedModel(team);
231    
232                    try {
233                            clearUsers.clear(team.getPrimaryKey());
234                    }
235                    catch (Exception e) {
236                            throw processException(e);
237                    }
238                    finally {
239                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
240                    }
241    
242                    Session session = null;
243    
244                    try {
245                            session = openSession();
246    
247                            if (team.isCachedModel() || BatchSessionUtil.isEnabled()) {
248                                    Object staleObject = session.get(TeamImpl.class,
249                                                    team.getPrimaryKeyObj());
250    
251                                    if (staleObject != null) {
252                                            session.evict(staleObject);
253                                    }
254                            }
255    
256                            session.delete(team);
257    
258                            session.flush();
259                    }
260                    catch (Exception e) {
261                            throw processException(e);
262                    }
263                    finally {
264                            closeSession(session);
265                    }
266    
267                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
268    
269                    TeamModelImpl teamModelImpl = (TeamModelImpl)team;
270    
271                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
272                            new Object[] {
273                                    new Long(teamModelImpl.getOriginalGroupId()),
274                                    
275                            teamModelImpl.getOriginalName()
276                            });
277    
278                    EntityCacheUtil.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
279                            TeamImpl.class, team.getPrimaryKey());
280    
281                    return team;
282            }
283    
284            public Team updateImpl(com.liferay.portal.model.Team team, boolean merge)
285                    throws SystemException {
286                    team = toUnwrappedModel(team);
287    
288                    boolean isNew = team.isNew();
289    
290                    TeamModelImpl teamModelImpl = (TeamModelImpl)team;
291    
292                    Session session = null;
293    
294                    try {
295                            session = openSession();
296    
297                            BatchSessionUtil.update(session, team, merge);
298    
299                            team.setNew(false);
300                    }
301                    catch (Exception e) {
302                            throw processException(e);
303                    }
304                    finally {
305                            closeSession(session);
306                    }
307    
308                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
309    
310                    EntityCacheUtil.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
311                            TeamImpl.class, team.getPrimaryKey(), team);
312    
313                    if (!isNew &&
314                                    ((team.getGroupId() != teamModelImpl.getOriginalGroupId()) ||
315                                    !Validator.equals(team.getName(),
316                                            teamModelImpl.getOriginalName()))) {
317                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_N,
318                                    new Object[] {
319                                            new Long(teamModelImpl.getOriginalGroupId()),
320                                            
321                                    teamModelImpl.getOriginalName()
322                                    });
323                    }
324    
325                    if (isNew ||
326                                    ((team.getGroupId() != teamModelImpl.getOriginalGroupId()) ||
327                                    !Validator.equals(team.getName(),
328                                            teamModelImpl.getOriginalName()))) {
329                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
330                                    new Object[] { new Long(team.getGroupId()), team.getName() },
331                                    team);
332                    }
333    
334                    return team;
335            }
336    
337            protected Team toUnwrappedModel(Team team) {
338                    if (team instanceof TeamImpl) {
339                            return team;
340                    }
341    
342                    TeamImpl teamImpl = new TeamImpl();
343    
344                    teamImpl.setNew(team.isNew());
345                    teamImpl.setPrimaryKey(team.getPrimaryKey());
346    
347                    teamImpl.setTeamId(team.getTeamId());
348                    teamImpl.setCompanyId(team.getCompanyId());
349                    teamImpl.setUserId(team.getUserId());
350                    teamImpl.setUserName(team.getUserName());
351                    teamImpl.setCreateDate(team.getCreateDate());
352                    teamImpl.setModifiedDate(team.getModifiedDate());
353                    teamImpl.setGroupId(team.getGroupId());
354                    teamImpl.setName(team.getName());
355                    teamImpl.setDescription(team.getDescription());
356    
357                    return teamImpl;
358            }
359    
360            /**
361             * Finds the team with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
362             *
363             * @param primaryKey the primary key of the team to find
364             * @return the team
365             * @throws com.liferay.portal.NoSuchModelException if a team with the primary key could not be found
366             * @throws SystemException if a system exception occurred
367             */
368            public Team findByPrimaryKey(Serializable primaryKey)
369                    throws NoSuchModelException, SystemException {
370                    return findByPrimaryKey(((Long)primaryKey).longValue());
371            }
372    
373            /**
374             * Finds the team with the primary key or throws a {@link com.liferay.portal.NoSuchTeamException} if it could not be found.
375             *
376             * @param teamId the primary key of the team to find
377             * @return the team
378             * @throws com.liferay.portal.NoSuchTeamException if a team with the primary key could not be found
379             * @throws SystemException if a system exception occurred
380             */
381            public Team findByPrimaryKey(long teamId)
382                    throws NoSuchTeamException, SystemException {
383                    Team team = fetchByPrimaryKey(teamId);
384    
385                    if (team == null) {
386                            if (_log.isWarnEnabled()) {
387                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + teamId);
388                            }
389    
390                            throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
391                                    teamId);
392                    }
393    
394                    return team;
395            }
396    
397            /**
398             * Finds the team with the primary key or returns <code>null</code> if it could not be found.
399             *
400             * @param primaryKey the primary key of the team to find
401             * @return the team, or <code>null</code> if a team with the primary key could not be found
402             * @throws SystemException if a system exception occurred
403             */
404            public Team fetchByPrimaryKey(Serializable primaryKey)
405                    throws SystemException {
406                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
407            }
408    
409            /**
410             * Finds the team with the primary key or returns <code>null</code> if it could not be found.
411             *
412             * @param teamId the primary key of the team to find
413             * @return the team, or <code>null</code> if a team with the primary key could not be found
414             * @throws SystemException if a system exception occurred
415             */
416            public Team fetchByPrimaryKey(long teamId) throws SystemException {
417                    Team team = (Team)EntityCacheUtil.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
418                                    TeamImpl.class, teamId, this);
419    
420                    if (team == null) {
421                            Session session = null;
422    
423                            try {
424                                    session = openSession();
425    
426                                    team = (Team)session.get(TeamImpl.class, new Long(teamId));
427                            }
428                            catch (Exception e) {
429                                    throw processException(e);
430                            }
431                            finally {
432                                    if (team != null) {
433                                            cacheResult(team);
434                                    }
435    
436                                    closeSession(session);
437                            }
438                    }
439    
440                    return team;
441            }
442    
443            /**
444             * Finds all the teams where groupId = &#63;.
445             *
446             * @param groupId the group id to search with
447             * @return the matching teams
448             * @throws SystemException if a system exception occurred
449             */
450            public List<Team> findByGroupId(long groupId) throws SystemException {
451                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
452            }
453    
454            /**
455             * Finds a range of all the teams where groupId = &#63;.
456             *
457             * <p>
458             * 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.
459             * </p>
460             *
461             * @param groupId the group id to search with
462             * @param start the lower bound of the range of teams to return
463             * @param end the upper bound of the range of teams to return (not inclusive)
464             * @return the range of matching teams
465             * @throws SystemException if a system exception occurred
466             */
467            public List<Team> findByGroupId(long groupId, int start, int end)
468                    throws SystemException {
469                    return findByGroupId(groupId, start, end, null);
470            }
471    
472            /**
473             * Finds an ordered range of all the teams where groupId = &#63;.
474             *
475             * <p>
476             * 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.
477             * </p>
478             *
479             * @param groupId the group id to search with
480             * @param start the lower bound of the range of teams to return
481             * @param end the upper bound of the range of teams to return (not inclusive)
482             * @param orderByComparator the comparator to order the results by
483             * @return the ordered range of matching teams
484             * @throws SystemException if a system exception occurred
485             */
486            public List<Team> findByGroupId(long groupId, int start, int end,
487                    OrderByComparator orderByComparator) throws SystemException {
488                    Object[] finderArgs = new Object[] {
489                                    groupId,
490                                    
491                                    String.valueOf(start), String.valueOf(end),
492                                    String.valueOf(orderByComparator)
493                            };
494    
495                    List<Team> list = (List<Team>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
496                                    finderArgs, this);
497    
498                    if (list == null) {
499                            Session session = null;
500    
501                            try {
502                                    session = openSession();
503    
504                                    StringBundler query = null;
505    
506                                    if (orderByComparator != null) {
507                                            query = new StringBundler(3 +
508                                                            (orderByComparator.getOrderByFields().length * 3));
509                                    }
510                                    else {
511                                            query = new StringBundler(3);
512                                    }
513    
514                                    query.append(_SQL_SELECT_TEAM_WHERE);
515    
516                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
517    
518                                    if (orderByComparator != null) {
519                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
520                                                    orderByComparator);
521                                    }
522    
523                                    else {
524                                            query.append(TeamModelImpl.ORDER_BY_JPQL);
525                                    }
526    
527                                    String sql = query.toString();
528    
529                                    Query q = session.createQuery(sql);
530    
531                                    QueryPos qPos = QueryPos.getInstance(q);
532    
533                                    qPos.add(groupId);
534    
535                                    list = (List<Team>)QueryUtil.list(q, getDialect(), start, end);
536                            }
537                            catch (Exception e) {
538                                    throw processException(e);
539                            }
540                            finally {
541                                    if (list == null) {
542                                            list = new ArrayList<Team>();
543                                    }
544    
545                                    cacheResult(list);
546    
547                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
548                                            finderArgs, list);
549    
550                                    closeSession(session);
551                            }
552                    }
553    
554                    return list;
555            }
556    
557            /**
558             * Finds the first team in the ordered set where groupId = &#63;.
559             *
560             * <p>
561             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
562             * </p>
563             *
564             * @param groupId the group id to search with
565             * @param orderByComparator the comparator to order the set by
566             * @return the first matching team
567             * @throws com.liferay.portal.NoSuchTeamException if a matching team could not be found
568             * @throws SystemException if a system exception occurred
569             */
570            public Team findByGroupId_First(long groupId,
571                    OrderByComparator orderByComparator)
572                    throws NoSuchTeamException, SystemException {
573                    List<Team> list = findByGroupId(groupId, 0, 1, orderByComparator);
574    
575                    if (list.isEmpty()) {
576                            StringBundler msg = new StringBundler(4);
577    
578                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
579    
580                            msg.append("groupId=");
581                            msg.append(groupId);
582    
583                            msg.append(StringPool.CLOSE_CURLY_BRACE);
584    
585                            throw new NoSuchTeamException(msg.toString());
586                    }
587                    else {
588                            return list.get(0);
589                    }
590            }
591    
592            /**
593             * Finds the last team in the ordered set where groupId = &#63;.
594             *
595             * <p>
596             * 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.
597             * </p>
598             *
599             * @param groupId the group id to search with
600             * @param orderByComparator the comparator to order the set by
601             * @return the last matching team
602             * @throws com.liferay.portal.NoSuchTeamException if a matching team could not be found
603             * @throws SystemException if a system exception occurred
604             */
605            public Team findByGroupId_Last(long groupId,
606                    OrderByComparator orderByComparator)
607                    throws NoSuchTeamException, SystemException {
608                    int count = countByGroupId(groupId);
609    
610                    List<Team> list = findByGroupId(groupId, count - 1, count,
611                                    orderByComparator);
612    
613                    if (list.isEmpty()) {
614                            StringBundler msg = new StringBundler(4);
615    
616                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
617    
618                            msg.append("groupId=");
619                            msg.append(groupId);
620    
621                            msg.append(StringPool.CLOSE_CURLY_BRACE);
622    
623                            throw new NoSuchTeamException(msg.toString());
624                    }
625                    else {
626                            return list.get(0);
627                    }
628            }
629    
630            /**
631             * Finds the teams before and after the current team in the ordered set where groupId = &#63;.
632             *
633             * <p>
634             * 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.
635             * </p>
636             *
637             * @param teamId the primary key of the current team
638             * @param groupId the group id to search with
639             * @param orderByComparator the comparator to order the set by
640             * @return the previous, current, and next team
641             * @throws com.liferay.portal.NoSuchTeamException if a team with the primary key could not be found
642             * @throws SystemException if a system exception occurred
643             */
644            public Team[] findByGroupId_PrevAndNext(long teamId, long groupId,
645                    OrderByComparator orderByComparator)
646                    throws NoSuchTeamException, SystemException {
647                    Team team = findByPrimaryKey(teamId);
648    
649                    Session session = null;
650    
651                    try {
652                            session = openSession();
653    
654                            Team[] array = new TeamImpl[3];
655    
656                            array[0] = getByGroupId_PrevAndNext(session, team, groupId,
657                                            orderByComparator, true);
658    
659                            array[1] = team;
660    
661                            array[2] = getByGroupId_PrevAndNext(session, team, groupId,
662                                            orderByComparator, false);
663    
664                            return array;
665                    }
666                    catch (Exception e) {
667                            throw processException(e);
668                    }
669                    finally {
670                            closeSession(session);
671                    }
672            }
673    
674            protected Team getByGroupId_PrevAndNext(Session session, Team team,
675                    long groupId, OrderByComparator orderByComparator, boolean previous) {
676                    StringBundler query = null;
677    
678                    if (orderByComparator != null) {
679                            query = new StringBundler(6 +
680                                            (orderByComparator.getOrderByFields().length * 6));
681                    }
682                    else {
683                            query = new StringBundler(3);
684                    }
685    
686                    query.append(_SQL_SELECT_TEAM_WHERE);
687    
688                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
689    
690                    if (orderByComparator != null) {
691                            String[] orderByFields = orderByComparator.getOrderByFields();
692    
693                            if (orderByFields.length > 0) {
694                                    query.append(WHERE_AND);
695                            }
696    
697                            for (int i = 0; i < orderByFields.length; i++) {
698                                    query.append(_ORDER_BY_ENTITY_ALIAS);
699                                    query.append(orderByFields[i]);
700    
701                                    if ((i + 1) < orderByFields.length) {
702                                            if (orderByComparator.isAscending() ^ previous) {
703                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
704                                            }
705                                            else {
706                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
707                                            }
708                                    }
709                                    else {
710                                            if (orderByComparator.isAscending() ^ previous) {
711                                                    query.append(WHERE_GREATER_THAN);
712                                            }
713                                            else {
714                                                    query.append(WHERE_LESSER_THAN);
715                                            }
716                                    }
717                            }
718    
719                            query.append(ORDER_BY_CLAUSE);
720    
721                            for (int i = 0; i < orderByFields.length; i++) {
722                                    query.append(_ORDER_BY_ENTITY_ALIAS);
723                                    query.append(orderByFields[i]);
724    
725                                    if ((i + 1) < orderByFields.length) {
726                                            if (orderByComparator.isAscending() ^ previous) {
727                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
728                                            }
729                                            else {
730                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
731                                            }
732                                    }
733                                    else {
734                                            if (orderByComparator.isAscending() ^ previous) {
735                                                    query.append(ORDER_BY_ASC);
736                                            }
737                                            else {
738                                                    query.append(ORDER_BY_DESC);
739                                            }
740                                    }
741                            }
742                    }
743    
744                    else {
745                            query.append(TeamModelImpl.ORDER_BY_JPQL);
746                    }
747    
748                    String sql = query.toString();
749    
750                    Query q = session.createQuery(sql);
751    
752                    q.setFirstResult(0);
753                    q.setMaxResults(2);
754    
755                    QueryPos qPos = QueryPos.getInstance(q);
756    
757                    qPos.add(groupId);
758    
759                    if (orderByComparator != null) {
760                            Object[] values = orderByComparator.getOrderByValues(team);
761    
762                            for (Object value : values) {
763                                    qPos.add(value);
764                            }
765                    }
766    
767                    List<Team> list = q.list();
768    
769                    if (list.size() == 2) {
770                            return list.get(1);
771                    }
772                    else {
773                            return null;
774                    }
775            }
776    
777            /**
778             * Filters by the user's permissions and finds all the teams where groupId = &#63;.
779             *
780             * @param groupId the group id to search with
781             * @return the matching teams that the user has permission to view
782             * @throws SystemException if a system exception occurred
783             */
784            public List<Team> filterFindByGroupId(long groupId)
785                    throws SystemException {
786                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
787                            QueryUtil.ALL_POS, null);
788            }
789    
790            /**
791             * Filters by the user's permissions and finds a range of all the teams where groupId = &#63;.
792             *
793             * <p>
794             * 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.
795             * </p>
796             *
797             * @param groupId the group id to search with
798             * @param start the lower bound of the range of teams to return
799             * @param end the upper bound of the range of teams to return (not inclusive)
800             * @return the range of matching teams that the user has permission to view
801             * @throws SystemException if a system exception occurred
802             */
803            public List<Team> filterFindByGroupId(long groupId, int start, int end)
804                    throws SystemException {
805                    return filterFindByGroupId(groupId, start, end, null);
806            }
807    
808            /**
809             * Filters by the user's permissions and finds an ordered range of all the teams where groupId = &#63;.
810             *
811             * <p>
812             * 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.
813             * </p>
814             *
815             * @param groupId the group id to search with
816             * @param start the lower bound of the range of teams to return
817             * @param end the upper bound of the range of teams to return (not inclusive)
818             * @param orderByComparator the comparator to order the results by
819             * @return the ordered range of matching teams that the user has permission to view
820             * @throws SystemException if a system exception occurred
821             */
822            public List<Team> filterFindByGroupId(long groupId, int start, int end,
823                    OrderByComparator orderByComparator) throws SystemException {
824                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
825                            return findByGroupId(groupId, start, end, orderByComparator);
826                    }
827    
828                    Session session = null;
829    
830                    try {
831                            session = openSession();
832    
833                            StringBundler query = null;
834    
835                            if (orderByComparator != null) {
836                                    query = new StringBundler(3 +
837                                                    (orderByComparator.getOrderByFields().length * 3));
838                            }
839                            else {
840                                    query = new StringBundler(3);
841                            }
842    
843                            query.append(_FILTER_SQL_SELECT_TEAM_WHERE);
844    
845                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
846    
847                            if (orderByComparator != null) {
848                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
849                                            orderByComparator);
850                            }
851    
852                            else {
853                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
854                            }
855    
856                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
857                                            Team.class.getName(), _FILTER_COLUMN_PK,
858                                            _FILTER_COLUMN_USERID, groupId);
859    
860                            SQLQuery q = session.createSQLQuery(sql);
861    
862                            q.addEntity(_FILTER_ENTITY_ALIAS, TeamImpl.class);
863    
864                            QueryPos qPos = QueryPos.getInstance(q);
865    
866                            qPos.add(groupId);
867    
868                            return (List<Team>)QueryUtil.list(q, getDialect(), start, end);
869                    }
870                    catch (Exception e) {
871                            throw processException(e);
872                    }
873                    finally {
874                            closeSession(session);
875                    }
876            }
877    
878            /**
879             * Finds the team where groupId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchTeamException} if it could not be found.
880             *
881             * @param groupId the group id to search with
882             * @param name the name to search with
883             * @return the matching team
884             * @throws com.liferay.portal.NoSuchTeamException if a matching team could not be found
885             * @throws SystemException if a system exception occurred
886             */
887            public Team findByG_N(long groupId, String name)
888                    throws NoSuchTeamException, SystemException {
889                    Team team = fetchByG_N(groupId, name);
890    
891                    if (team == null) {
892                            StringBundler msg = new StringBundler(6);
893    
894                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
895    
896                            msg.append("groupId=");
897                            msg.append(groupId);
898    
899                            msg.append(", name=");
900                            msg.append(name);
901    
902                            msg.append(StringPool.CLOSE_CURLY_BRACE);
903    
904                            if (_log.isWarnEnabled()) {
905                                    _log.warn(msg.toString());
906                            }
907    
908                            throw new NoSuchTeamException(msg.toString());
909                    }
910    
911                    return team;
912            }
913    
914            /**
915             * Finds the team where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
916             *
917             * @param groupId the group id to search with
918             * @param name the name to search with
919             * @return the matching team, or <code>null</code> if a matching team could not be found
920             * @throws SystemException if a system exception occurred
921             */
922            public Team fetchByG_N(long groupId, String name) throws SystemException {
923                    return fetchByG_N(groupId, name, true);
924            }
925    
926            /**
927             * Finds the team where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
928             *
929             * @param groupId the group id to search with
930             * @param name the name to search with
931             * @return the matching team, or <code>null</code> if a matching team could not be found
932             * @throws SystemException if a system exception occurred
933             */
934            public Team fetchByG_N(long groupId, String name, boolean retrieveFromCache)
935                    throws SystemException {
936                    Object[] finderArgs = new Object[] { groupId, name };
937    
938                    Object result = null;
939    
940                    if (retrieveFromCache) {
941                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_N,
942                                            finderArgs, this);
943                    }
944    
945                    if (result == null) {
946                            Session session = null;
947    
948                            try {
949                                    session = openSession();
950    
951                                    StringBundler query = new StringBundler(4);
952    
953                                    query.append(_SQL_SELECT_TEAM_WHERE);
954    
955                                    query.append(_FINDER_COLUMN_G_N_GROUPID_2);
956    
957                                    if (name == null) {
958                                            query.append(_FINDER_COLUMN_G_N_NAME_1);
959                                    }
960                                    else {
961                                            if (name.equals(StringPool.BLANK)) {
962                                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
963                                            }
964                                            else {
965                                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
966                                            }
967                                    }
968    
969                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
970    
971                                    String sql = query.toString();
972    
973                                    Query q = session.createQuery(sql);
974    
975                                    QueryPos qPos = QueryPos.getInstance(q);
976    
977                                    qPos.add(groupId);
978    
979                                    if (name != null) {
980                                            qPos.add(name);
981                                    }
982    
983                                    List<Team> list = q.list();
984    
985                                    result = list;
986    
987                                    Team team = null;
988    
989                                    if (list.isEmpty()) {
990                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
991                                                    finderArgs, list);
992                                    }
993                                    else {
994                                            team = list.get(0);
995    
996                                            cacheResult(team);
997    
998                                            if ((team.getGroupId() != groupId) ||
999                                                            (team.getName() == null) ||
1000                                                            !team.getName().equals(name)) {
1001                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1002                                                            finderArgs, team);
1003                                            }
1004                                    }
1005    
1006                                    return team;
1007                            }
1008                            catch (Exception e) {
1009                                    throw processException(e);
1010                            }
1011                            finally {
1012                                    if (result == null) {
1013                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_N,
1014                                                    finderArgs, new ArrayList<Team>());
1015                                    }
1016    
1017                                    closeSession(session);
1018                            }
1019                    }
1020                    else {
1021                            if (result instanceof List<?>) {
1022                                    return null;
1023                            }
1024                            else {
1025                                    return (Team)result;
1026                            }
1027                    }
1028            }
1029    
1030            /**
1031             * Finds all the teams.
1032             *
1033             * @return the teams
1034             * @throws SystemException if a system exception occurred
1035             */
1036            public List<Team> findAll() throws SystemException {
1037                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1038            }
1039    
1040            /**
1041             * Finds a range of all the teams.
1042             *
1043             * <p>
1044             * 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.
1045             * </p>
1046             *
1047             * @param start the lower bound of the range of teams to return
1048             * @param end the upper bound of the range of teams to return (not inclusive)
1049             * @return the range of teams
1050             * @throws SystemException if a system exception occurred
1051             */
1052            public List<Team> findAll(int start, int end) throws SystemException {
1053                    return findAll(start, end, null);
1054            }
1055    
1056            /**
1057             * Finds an ordered range of all the teams.
1058             *
1059             * <p>
1060             * 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.
1061             * </p>
1062             *
1063             * @param start the lower bound of the range of teams to return
1064             * @param end the upper bound of the range of teams to return (not inclusive)
1065             * @param orderByComparator the comparator to order the results by
1066             * @return the ordered range of teams
1067             * @throws SystemException if a system exception occurred
1068             */
1069            public List<Team> findAll(int start, int end,
1070                    OrderByComparator orderByComparator) throws SystemException {
1071                    Object[] finderArgs = new Object[] {
1072                                    String.valueOf(start), String.valueOf(end),
1073                                    String.valueOf(orderByComparator)
1074                            };
1075    
1076                    List<Team> list = (List<Team>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1077                                    finderArgs, this);
1078    
1079                    if (list == null) {
1080                            Session session = null;
1081    
1082                            try {
1083                                    session = openSession();
1084    
1085                                    StringBundler query = null;
1086                                    String sql = null;
1087    
1088                                    if (orderByComparator != null) {
1089                                            query = new StringBundler(2 +
1090                                                            (orderByComparator.getOrderByFields().length * 3));
1091    
1092                                            query.append(_SQL_SELECT_TEAM);
1093    
1094                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1095                                                    orderByComparator);
1096    
1097                                            sql = query.toString();
1098                                    }
1099                                    else {
1100                                            sql = _SQL_SELECT_TEAM.concat(TeamModelImpl.ORDER_BY_JPQL);
1101                                    }
1102    
1103                                    Query q = session.createQuery(sql);
1104    
1105                                    if (orderByComparator == null) {
1106                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1107                                                            end, false);
1108    
1109                                            Collections.sort(list);
1110                                    }
1111                                    else {
1112                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1113                                                            end);
1114                                    }
1115                            }
1116                            catch (Exception e) {
1117                                    throw processException(e);
1118                            }
1119                            finally {
1120                                    if (list == null) {
1121                                            list = new ArrayList<Team>();
1122                                    }
1123    
1124                                    cacheResult(list);
1125    
1126                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1127    
1128                                    closeSession(session);
1129                            }
1130                    }
1131    
1132                    return list;
1133            }
1134    
1135            /**
1136             * Removes all the teams where groupId = &#63; from the database.
1137             *
1138             * @param groupId the group id to search with
1139             * @throws SystemException if a system exception occurred
1140             */
1141            public void removeByGroupId(long groupId) throws SystemException {
1142                    for (Team team : findByGroupId(groupId)) {
1143                            remove(team);
1144                    }
1145            }
1146    
1147            /**
1148             * Removes the team where groupId = &#63; and name = &#63; from the database.
1149             *
1150             * @param groupId the group id to search with
1151             * @param name the name to search with
1152             * @throws SystemException if a system exception occurred
1153             */
1154            public void removeByG_N(long groupId, String name)
1155                    throws NoSuchTeamException, SystemException {
1156                    Team team = findByG_N(groupId, name);
1157    
1158                    remove(team);
1159            }
1160    
1161            /**
1162             * Removes all the teams from the database.
1163             *
1164             * @throws SystemException if a system exception occurred
1165             */
1166            public void removeAll() throws SystemException {
1167                    for (Team team : findAll()) {
1168                            remove(team);
1169                    }
1170            }
1171    
1172            /**
1173             * Counts all the teams where groupId = &#63;.
1174             *
1175             * @param groupId the group id to search with
1176             * @return the number of matching teams
1177             * @throws SystemException if a system exception occurred
1178             */
1179            public int countByGroupId(long groupId) throws SystemException {
1180                    Object[] finderArgs = new Object[] { groupId };
1181    
1182                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1183                                    finderArgs, this);
1184    
1185                    if (count == null) {
1186                            Session session = null;
1187    
1188                            try {
1189                                    session = openSession();
1190    
1191                                    StringBundler query = new StringBundler(2);
1192    
1193                                    query.append(_SQL_COUNT_TEAM_WHERE);
1194    
1195                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1196    
1197                                    String sql = query.toString();
1198    
1199                                    Query q = session.createQuery(sql);
1200    
1201                                    QueryPos qPos = QueryPos.getInstance(q);
1202    
1203                                    qPos.add(groupId);
1204    
1205                                    count = (Long)q.uniqueResult();
1206                            }
1207                            catch (Exception e) {
1208                                    throw processException(e);
1209                            }
1210                            finally {
1211                                    if (count == null) {
1212                                            count = Long.valueOf(0);
1213                                    }
1214    
1215                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1216                                            finderArgs, count);
1217    
1218                                    closeSession(session);
1219                            }
1220                    }
1221    
1222                    return count.intValue();
1223            }
1224    
1225            /**
1226             * Filters by the user's permissions and counts all the teams where groupId = &#63;.
1227             *
1228             * @param groupId the group id to search with
1229             * @return the number of matching teams that the user has permission to view
1230             * @throws SystemException if a system exception occurred
1231             */
1232            public int filterCountByGroupId(long groupId) throws SystemException {
1233                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1234                            return countByGroupId(groupId);
1235                    }
1236    
1237                    Session session = null;
1238    
1239                    try {
1240                            session = openSession();
1241    
1242                            StringBundler query = new StringBundler(2);
1243    
1244                            query.append(_FILTER_SQL_COUNT_TEAM_WHERE);
1245    
1246                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1247    
1248                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1249                                            Team.class.getName(), _FILTER_COLUMN_PK,
1250                                            _FILTER_COLUMN_USERID, groupId);
1251    
1252                            SQLQuery q = session.createSQLQuery(sql);
1253    
1254                            q.addScalar(COUNT_COLUMN_NAME,
1255                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1256    
1257                            QueryPos qPos = QueryPos.getInstance(q);
1258    
1259                            qPos.add(groupId);
1260    
1261                            Long count = (Long)q.uniqueResult();
1262    
1263                            return count.intValue();
1264                    }
1265                    catch (Exception e) {
1266                            throw processException(e);
1267                    }
1268                    finally {
1269                            closeSession(session);
1270                    }
1271            }
1272    
1273            /**
1274             * Counts all the teams where groupId = &#63; and name = &#63;.
1275             *
1276             * @param groupId the group id to search with
1277             * @param name the name to search with
1278             * @return the number of matching teams
1279             * @throws SystemException if a system exception occurred
1280             */
1281            public int countByG_N(long groupId, String name) throws SystemException {
1282                    Object[] finderArgs = new Object[] { groupId, name };
1283    
1284                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_N,
1285                                    finderArgs, this);
1286    
1287                    if (count == null) {
1288                            Session session = null;
1289    
1290                            try {
1291                                    session = openSession();
1292    
1293                                    StringBundler query = new StringBundler(3);
1294    
1295                                    query.append(_SQL_COUNT_TEAM_WHERE);
1296    
1297                                    query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1298    
1299                                    if (name == null) {
1300                                            query.append(_FINDER_COLUMN_G_N_NAME_1);
1301                                    }
1302                                    else {
1303                                            if (name.equals(StringPool.BLANK)) {
1304                                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
1305                                            }
1306                                            else {
1307                                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
1308                                            }
1309                                    }
1310    
1311                                    String sql = query.toString();
1312    
1313                                    Query q = session.createQuery(sql);
1314    
1315                                    QueryPos qPos = QueryPos.getInstance(q);
1316    
1317                                    qPos.add(groupId);
1318    
1319                                    if (name != null) {
1320                                            qPos.add(name);
1321                                    }
1322    
1323                                    count = (Long)q.uniqueResult();
1324                            }
1325                            catch (Exception e) {
1326                                    throw processException(e);
1327                            }
1328                            finally {
1329                                    if (count == null) {
1330                                            count = Long.valueOf(0);
1331                                    }
1332    
1333                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_N, finderArgs,
1334                                            count);
1335    
1336                                    closeSession(session);
1337                            }
1338                    }
1339    
1340                    return count.intValue();
1341            }
1342    
1343            /**
1344             * Filters by the user's permissions and counts all the teams where groupId = &#63; and name = &#63;.
1345             *
1346             * @param groupId the group id to search with
1347             * @param name the name to search with
1348             * @return the number of matching teams that the user has permission to view
1349             * @throws SystemException if a system exception occurred
1350             */
1351            public int filterCountByG_N(long groupId, String name)
1352                    throws SystemException {
1353                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1354                            return countByG_N(groupId, name);
1355                    }
1356    
1357                    Session session = null;
1358    
1359                    try {
1360                            session = openSession();
1361    
1362                            StringBundler query = new StringBundler(3);
1363    
1364                            query.append(_FILTER_SQL_COUNT_TEAM_WHERE);
1365    
1366                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
1367    
1368                            if (name == null) {
1369                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
1370                            }
1371                            else {
1372                                    if (name.equals(StringPool.BLANK)) {
1373                                            query.append(_FINDER_COLUMN_G_N_NAME_3);
1374                                    }
1375                                    else {
1376                                            query.append(_FINDER_COLUMN_G_N_NAME_2);
1377                                    }
1378                            }
1379    
1380                            String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1381                                            Team.class.getName(), _FILTER_COLUMN_PK,
1382                                            _FILTER_COLUMN_USERID, groupId);
1383    
1384                            SQLQuery q = session.createSQLQuery(sql);
1385    
1386                            q.addScalar(COUNT_COLUMN_NAME,
1387                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1388    
1389                            QueryPos qPos = QueryPos.getInstance(q);
1390    
1391                            qPos.add(groupId);
1392    
1393                            if (name != null) {
1394                                    qPos.add(name);
1395                            }
1396    
1397                            Long count = (Long)q.uniqueResult();
1398    
1399                            return count.intValue();
1400                    }
1401                    catch (Exception e) {
1402                            throw processException(e);
1403                    }
1404                    finally {
1405                            closeSession(session);
1406                    }
1407            }
1408    
1409            /**
1410             * Counts all the teams.
1411             *
1412             * @return the number of teams
1413             * @throws SystemException if a system exception occurred
1414             */
1415            public int countAll() throws SystemException {
1416                    Object[] finderArgs = new Object[0];
1417    
1418                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1419                                    finderArgs, this);
1420    
1421                    if (count == null) {
1422                            Session session = null;
1423    
1424                            try {
1425                                    session = openSession();
1426    
1427                                    Query q = session.createQuery(_SQL_COUNT_TEAM);
1428    
1429                                    count = (Long)q.uniqueResult();
1430                            }
1431                            catch (Exception e) {
1432                                    throw processException(e);
1433                            }
1434                            finally {
1435                                    if (count == null) {
1436                                            count = Long.valueOf(0);
1437                                    }
1438    
1439                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1440                                            count);
1441    
1442                                    closeSession(session);
1443                            }
1444                    }
1445    
1446                    return count.intValue();
1447            }
1448    
1449            /**
1450             * Gets all the users associated with the team.
1451             *
1452             * @param pk the primary key of the team to get the associated users for
1453             * @return the users associated with the team
1454             * @throws SystemException if a system exception occurred
1455             */
1456            public List<com.liferay.portal.model.User> getUsers(long pk)
1457                    throws SystemException {
1458                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1459            }
1460    
1461            /**
1462             * Gets a range of all the users associated with the team.
1463             *
1464             * <p>
1465             * 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.
1466             * </p>
1467             *
1468             * @param pk the primary key of the team to get the associated users for
1469             * @param start the lower bound of the range of teams to return
1470             * @param end the upper bound of the range of teams to return (not inclusive)
1471             * @return the range of users associated with the team
1472             * @throws SystemException if a system exception occurred
1473             */
1474            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1475                    int end) throws SystemException {
1476                    return getUsers(pk, start, end, null);
1477            }
1478    
1479            public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1480                            TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS,
1481                            TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "getUsers",
1482                            new String[] {
1483                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1484                                    "com.liferay.portal.kernel.util.OrderByComparator"
1485                            });
1486    
1487            /**
1488             * Gets an ordered range of all the users associated with the team.
1489             *
1490             * <p>
1491             * 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.
1492             * </p>
1493             *
1494             * @param pk the primary key of the team to get the associated users for
1495             * @param start the lower bound of the range of teams to return
1496             * @param end the upper bound of the range of teams to return (not inclusive)
1497             * @param orderByComparator the comparator to order the results by
1498             * @return the ordered range of users associated with the team
1499             * @throws SystemException if a system exception occurred
1500             */
1501            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1502                    int end, OrderByComparator orderByComparator) throws SystemException {
1503                    Object[] finderArgs = new Object[] {
1504                                    pk, String.valueOf(start), String.valueOf(end),
1505                                    String.valueOf(orderByComparator)
1506                            };
1507    
1508                    List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1509                                    finderArgs, this);
1510    
1511                    if (list == null) {
1512                            Session session = null;
1513    
1514                            try {
1515                                    session = openSession();
1516    
1517                                    String sql = null;
1518    
1519                                    if (orderByComparator != null) {
1520                                            sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
1521                                                                               .concat(orderByComparator.getOrderBy());
1522                                    }
1523                                    else {
1524                                            sql = _SQL_GETUSERS;
1525                                    }
1526    
1527                                    SQLQuery q = session.createSQLQuery(sql);
1528    
1529                                    q.addEntity("User_",
1530                                            com.liferay.portal.model.impl.UserImpl.class);
1531    
1532                                    QueryPos qPos = QueryPos.getInstance(q);
1533    
1534                                    qPos.add(pk);
1535    
1536                                    list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1537                                                    getDialect(), start, end);
1538                            }
1539                            catch (Exception e) {
1540                                    throw processException(e);
1541                            }
1542                            finally {
1543                                    if (list == null) {
1544                                            list = new ArrayList<com.liferay.portal.model.User>();
1545                                    }
1546    
1547                                    userPersistence.cacheResult(list);
1548    
1549                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1550                                            list);
1551    
1552                                    closeSession(session);
1553                            }
1554                    }
1555    
1556                    return list;
1557            }
1558    
1559            public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1560                            TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS,
1561                            TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "getUsersSize",
1562                            new String[] { Long.class.getName() });
1563    
1564            /**
1565             * Gets the number of users associated with the team.
1566             *
1567             * @param pk the primary key of the team to get the number of associated users for
1568             * @return the number of users associated with the team
1569             * @throws SystemException if a system exception occurred
1570             */
1571            public int getUsersSize(long pk) throws SystemException {
1572                    Object[] finderArgs = new Object[] { pk };
1573    
1574                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1575                                    finderArgs, this);
1576    
1577                    if (count == null) {
1578                            Session session = null;
1579    
1580                            try {
1581                                    session = openSession();
1582    
1583                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1584    
1585                                    q.addScalar(COUNT_COLUMN_NAME,
1586                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
1587    
1588                                    QueryPos qPos = QueryPos.getInstance(q);
1589    
1590                                    qPos.add(pk);
1591    
1592                                    count = (Long)q.uniqueResult();
1593                            }
1594                            catch (Exception e) {
1595                                    throw processException(e);
1596                            }
1597                            finally {
1598                                    if (count == null) {
1599                                            count = Long.valueOf(0);
1600                                    }
1601    
1602                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1603                                            finderArgs, count);
1604    
1605                                    closeSession(session);
1606                            }
1607                    }
1608    
1609                    return count.intValue();
1610            }
1611    
1612            public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1613                            TeamModelImpl.FINDER_CACHE_ENABLED_USERS_TEAMS,
1614                            TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME, "containsUser",
1615                            new String[] { Long.class.getName(), Long.class.getName() });
1616    
1617            /**
1618             * Determines whether the user is associated with the team.
1619             *
1620             * @param pk the primary key of the team
1621             * @param userPK the primary key of the user
1622             * @return whether the user is associated with the team
1623             * @throws SystemException if a system exception occurred
1624             */
1625            public boolean containsUser(long pk, long userPK) throws SystemException {
1626                    Object[] finderArgs = new Object[] { pk, userPK };
1627    
1628                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1629                                    finderArgs, this);
1630    
1631                    if (value == null) {
1632                            try {
1633                                    value = Boolean.valueOf(containsUser.contains(pk, userPK));
1634                            }
1635                            catch (Exception e) {
1636                                    throw processException(e);
1637                            }
1638                            finally {
1639                                    if (value == null) {
1640                                            value = Boolean.FALSE;
1641                                    }
1642    
1643                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1644                                            finderArgs, value);
1645                            }
1646                    }
1647    
1648                    return value.booleanValue();
1649            }
1650    
1651            /**
1652             * Determines whether the team has any users associated with it.
1653             *
1654             * @param pk the primary key of the team to check for associations with users
1655             * @return whether the team has any users associated with it
1656             * @throws SystemException if a system exception occurred
1657             */
1658            public boolean containsUsers(long pk) throws SystemException {
1659                    if (getUsersSize(pk) > 0) {
1660                            return true;
1661                    }
1662                    else {
1663                            return false;
1664                    }
1665            }
1666    
1667            /**
1668             * Adds an association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1669             *
1670             * @param pk the primary key of the team
1671             * @param userPK the primary key of the user
1672             * @throws SystemException if a system exception occurred
1673             */
1674            public void addUser(long pk, long userPK) throws SystemException {
1675                    try {
1676                            addUser.add(pk, userPK);
1677                    }
1678                    catch (Exception e) {
1679                            throw processException(e);
1680                    }
1681                    finally {
1682                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1683                    }
1684            }
1685    
1686            /**
1687             * Adds an association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1688             *
1689             * @param pk the primary key of the team
1690             * @param user the user
1691             * @throws SystemException if a system exception occurred
1692             */
1693            public void addUser(long pk, com.liferay.portal.model.User user)
1694                    throws SystemException {
1695                    try {
1696                            addUser.add(pk, user.getPrimaryKey());
1697                    }
1698                    catch (Exception e) {
1699                            throw processException(e);
1700                    }
1701                    finally {
1702                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1703                    }
1704            }
1705    
1706            /**
1707             * Adds an association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1708             *
1709             * @param pk the primary key of the team
1710             * @param userPKs the primary keys of the users
1711             * @throws SystemException if a system exception occurred
1712             */
1713            public void addUsers(long pk, long[] userPKs) throws SystemException {
1714                    try {
1715                            for (long userPK : userPKs) {
1716                                    addUser.add(pk, userPK);
1717                            }
1718                    }
1719                    catch (Exception e) {
1720                            throw processException(e);
1721                    }
1722                    finally {
1723                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1724                    }
1725            }
1726    
1727            /**
1728             * Adds an association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1729             *
1730             * @param pk the primary key of the team
1731             * @param users the users
1732             * @throws SystemException if a system exception occurred
1733             */
1734            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1735                    throws SystemException {
1736                    try {
1737                            for (com.liferay.portal.model.User user : users) {
1738                                    addUser.add(pk, user.getPrimaryKey());
1739                            }
1740                    }
1741                    catch (Exception e) {
1742                            throw processException(e);
1743                    }
1744                    finally {
1745                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1746                    }
1747            }
1748    
1749            /**
1750             * Clears all associations between the team and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1751             *
1752             * @param pk the primary key of the team to clear the associated users from
1753             * @throws SystemException if a system exception occurred
1754             */
1755            public void clearUsers(long pk) throws SystemException {
1756                    try {
1757                            clearUsers.clear(pk);
1758                    }
1759                    catch (Exception e) {
1760                            throw processException(e);
1761                    }
1762                    finally {
1763                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1764                    }
1765            }
1766    
1767            /**
1768             * Removes the association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1769             *
1770             * @param pk the primary key of the team
1771             * @param userPK the primary key of the user
1772             * @throws SystemException if a system exception occurred
1773             */
1774            public void removeUser(long pk, long userPK) throws SystemException {
1775                    try {
1776                            removeUser.remove(pk, userPK);
1777                    }
1778                    catch (Exception e) {
1779                            throw processException(e);
1780                    }
1781                    finally {
1782                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1783                    }
1784            }
1785    
1786            /**
1787             * Removes the association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1788             *
1789             * @param pk the primary key of the team
1790             * @param user the user
1791             * @throws SystemException if a system exception occurred
1792             */
1793            public void removeUser(long pk, com.liferay.portal.model.User user)
1794                    throws SystemException {
1795                    try {
1796                            removeUser.remove(pk, user.getPrimaryKey());
1797                    }
1798                    catch (Exception e) {
1799                            throw processException(e);
1800                    }
1801                    finally {
1802                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1803                    }
1804            }
1805    
1806            /**
1807             * Removes the association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1808             *
1809             * @param pk the primary key of the team
1810             * @param userPKs the primary keys of the users
1811             * @throws SystemException if a system exception occurred
1812             */
1813            public void removeUsers(long pk, long[] userPKs) throws SystemException {
1814                    try {
1815                            for (long userPK : userPKs) {
1816                                    removeUser.remove(pk, userPK);
1817                            }
1818                    }
1819                    catch (Exception e) {
1820                            throw processException(e);
1821                    }
1822                    finally {
1823                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1824                    }
1825            }
1826    
1827            /**
1828             * Removes the association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
1829             *
1830             * @param pk the primary key of the team
1831             * @param users the users
1832             * @throws SystemException if a system exception occurred
1833             */
1834            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
1835                    throws SystemException {
1836                    try {
1837                            for (com.liferay.portal.model.User user : users) {
1838                                    removeUser.remove(pk, user.getPrimaryKey());
1839                            }
1840                    }
1841                    catch (Exception e) {
1842                            throw processException(e);
1843                    }
1844                    finally {
1845                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1846                    }
1847            }
1848    
1849            /**
1850             * 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.
1851             *
1852             * @param pk the primary key of the team to set the associations for
1853             * @param userPKs the primary keys of the users to be associated with the team
1854             * @throws SystemException if a system exception occurred
1855             */
1856            public void setUsers(long pk, long[] userPKs) throws SystemException {
1857                    try {
1858                            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
1859    
1860                            List<com.liferay.portal.model.User> users = getUsers(pk);
1861    
1862                            for (com.liferay.portal.model.User user : users) {
1863                                    if (!userPKSet.remove(user.getPrimaryKey())) {
1864                                            removeUser.remove(pk, user.getPrimaryKey());
1865                                    }
1866                            }
1867    
1868                            for (Long userPK : userPKSet) {
1869                                    addUser.add(pk, userPK);
1870                            }
1871                    }
1872                    catch (Exception e) {
1873                            throw processException(e);
1874                    }
1875                    finally {
1876                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1877                    }
1878            }
1879    
1880            /**
1881             * 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.
1882             *
1883             * @param pk the primary key of the team to set the associations for
1884             * @param users the users to be associated with the team
1885             * @throws SystemException if a system exception occurred
1886             */
1887            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
1888                    throws SystemException {
1889                    try {
1890                            long[] userPKs = new long[users.size()];
1891    
1892                            for (int i = 0; i < users.size(); i++) {
1893                                    com.liferay.portal.model.User user = users.get(i);
1894    
1895                                    userPKs[i] = user.getPrimaryKey();
1896                            }
1897    
1898                            setUsers(pk, userPKs);
1899                    }
1900                    catch (Exception e) {
1901                            throw processException(e);
1902                    }
1903                    finally {
1904                            FinderCacheUtil.clearCache(TeamModelImpl.MAPPING_TABLE_USERS_TEAMS_NAME);
1905                    }
1906            }
1907    
1908            /**
1909             * Initializes the team persistence.
1910             */
1911            public void afterPropertiesSet() {
1912                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1913                                            com.liferay.portal.util.PropsUtil.get(
1914                                                    "value.object.listener.com.liferay.portal.model.Team")));
1915    
1916                    if (listenerClassNames.length > 0) {
1917                            try {
1918                                    List<ModelListener<Team>> listenersList = new ArrayList<ModelListener<Team>>();
1919    
1920                                    for (String listenerClassName : listenerClassNames) {
1921                                            listenersList.add((ModelListener<Team>)InstanceFactory.newInstance(
1922                                                            listenerClassName));
1923                                    }
1924    
1925                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1926                            }
1927                            catch (Exception e) {
1928                                    _log.error(e);
1929                            }
1930                    }
1931    
1932                    containsUser = new ContainsUser(this);
1933    
1934                    addUser = new AddUser(this);
1935                    clearUsers = new ClearUsers(this);
1936                    removeUser = new RemoveUser(this);
1937            }
1938    
1939            @BeanReference(type = AccountPersistence.class)
1940            protected AccountPersistence accountPersistence;
1941            @BeanReference(type = AddressPersistence.class)
1942            protected AddressPersistence addressPersistence;
1943            @BeanReference(type = BrowserTrackerPersistence.class)
1944            protected BrowserTrackerPersistence browserTrackerPersistence;
1945            @BeanReference(type = ClassNamePersistence.class)
1946            protected ClassNamePersistence classNamePersistence;
1947            @BeanReference(type = ClusterGroupPersistence.class)
1948            protected ClusterGroupPersistence clusterGroupPersistence;
1949            @BeanReference(type = CompanyPersistence.class)
1950            protected CompanyPersistence companyPersistence;
1951            @BeanReference(type = ContactPersistence.class)
1952            protected ContactPersistence contactPersistence;
1953            @BeanReference(type = CountryPersistence.class)
1954            protected CountryPersistence countryPersistence;
1955            @BeanReference(type = EmailAddressPersistence.class)
1956            protected EmailAddressPersistence emailAddressPersistence;
1957            @BeanReference(type = GroupPersistence.class)
1958            protected GroupPersistence groupPersistence;
1959            @BeanReference(type = ImagePersistence.class)
1960            protected ImagePersistence imagePersistence;
1961            @BeanReference(type = LayoutPersistence.class)
1962            protected LayoutPersistence layoutPersistence;
1963            @BeanReference(type = LayoutPrototypePersistence.class)
1964            protected LayoutPrototypePersistence layoutPrototypePersistence;
1965            @BeanReference(type = LayoutSetPersistence.class)
1966            protected LayoutSetPersistence layoutSetPersistence;
1967            @BeanReference(type = LayoutSetPrototypePersistence.class)
1968            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1969            @BeanReference(type = ListTypePersistence.class)
1970            protected ListTypePersistence listTypePersistence;
1971            @BeanReference(type = LockPersistence.class)
1972            protected LockPersistence lockPersistence;
1973            @BeanReference(type = MembershipRequestPersistence.class)
1974            protected MembershipRequestPersistence membershipRequestPersistence;
1975            @BeanReference(type = OrganizationPersistence.class)
1976            protected OrganizationPersistence organizationPersistence;
1977            @BeanReference(type = OrgGroupPermissionPersistence.class)
1978            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1979            @BeanReference(type = OrgGroupRolePersistence.class)
1980            protected OrgGroupRolePersistence orgGroupRolePersistence;
1981            @BeanReference(type = OrgLaborPersistence.class)
1982            protected OrgLaborPersistence orgLaborPersistence;
1983            @BeanReference(type = PasswordPolicyPersistence.class)
1984            protected PasswordPolicyPersistence passwordPolicyPersistence;
1985            @BeanReference(type = PasswordPolicyRelPersistence.class)
1986            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1987            @BeanReference(type = PasswordTrackerPersistence.class)
1988            protected PasswordTrackerPersistence passwordTrackerPersistence;
1989            @BeanReference(type = PermissionPersistence.class)
1990            protected PermissionPersistence permissionPersistence;
1991            @BeanReference(type = PhonePersistence.class)
1992            protected PhonePersistence phonePersistence;
1993            @BeanReference(type = PluginSettingPersistence.class)
1994            protected PluginSettingPersistence pluginSettingPersistence;
1995            @BeanReference(type = PortletPersistence.class)
1996            protected PortletPersistence portletPersistence;
1997            @BeanReference(type = PortletItemPersistence.class)
1998            protected PortletItemPersistence portletItemPersistence;
1999            @BeanReference(type = PortletPreferencesPersistence.class)
2000            protected PortletPreferencesPersistence portletPreferencesPersistence;
2001            @BeanReference(type = RegionPersistence.class)
2002            protected RegionPersistence regionPersistence;
2003            @BeanReference(type = ReleasePersistence.class)
2004            protected ReleasePersistence releasePersistence;
2005            @BeanReference(type = ResourcePersistence.class)
2006            protected ResourcePersistence resourcePersistence;
2007            @BeanReference(type = ResourceActionPersistence.class)
2008            protected ResourceActionPersistence resourceActionPersistence;
2009            @BeanReference(type = ResourceCodePersistence.class)
2010            protected ResourceCodePersistence resourceCodePersistence;
2011            @BeanReference(type = ResourcePermissionPersistence.class)
2012            protected ResourcePermissionPersistence resourcePermissionPersistence;
2013            @BeanReference(type = RolePersistence.class)
2014            protected RolePersistence rolePersistence;
2015            @BeanReference(type = ServiceComponentPersistence.class)
2016            protected ServiceComponentPersistence serviceComponentPersistence;
2017            @BeanReference(type = ShardPersistence.class)
2018            protected ShardPersistence shardPersistence;
2019            @BeanReference(type = SubscriptionPersistence.class)
2020            protected SubscriptionPersistence subscriptionPersistence;
2021            @BeanReference(type = TicketPersistence.class)
2022            protected TicketPersistence ticketPersistence;
2023            @BeanReference(type = TeamPersistence.class)
2024            protected TeamPersistence teamPersistence;
2025            @BeanReference(type = UserPersistence.class)
2026            protected UserPersistence userPersistence;
2027            @BeanReference(type = UserGroupPersistence.class)
2028            protected UserGroupPersistence userGroupPersistence;
2029            @BeanReference(type = UserGroupGroupRolePersistence.class)
2030            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2031            @BeanReference(type = UserGroupRolePersistence.class)
2032            protected UserGroupRolePersistence userGroupRolePersistence;
2033            @BeanReference(type = UserIdMapperPersistence.class)
2034            protected UserIdMapperPersistence userIdMapperPersistence;
2035            @BeanReference(type = UserTrackerPersistence.class)
2036            protected UserTrackerPersistence userTrackerPersistence;
2037            @BeanReference(type = UserTrackerPathPersistence.class)
2038            protected UserTrackerPathPersistence userTrackerPathPersistence;
2039            @BeanReference(type = WebDAVPropsPersistence.class)
2040            protected WebDAVPropsPersistence webDAVPropsPersistence;
2041            @BeanReference(type = WebsitePersistence.class)
2042            protected WebsitePersistence websitePersistence;
2043            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2044            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2045            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2046            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2047            protected ContainsUser containsUser;
2048            protected AddUser addUser;
2049            protected ClearUsers clearUsers;
2050            protected RemoveUser removeUser;
2051    
2052            protected class ContainsUser {
2053                    protected ContainsUser(TeamPersistenceImpl persistenceImpl) {
2054                            super();
2055    
2056                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2057                                            _SQL_CONTAINSUSER,
2058                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2059                                            RowMapper.COUNT);
2060                    }
2061    
2062                    protected boolean contains(long teamId, long userId) {
2063                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2064                                                    new Long(teamId), new Long(userId)
2065                                            });
2066    
2067                            if (results.size() > 0) {
2068                                    Integer count = results.get(0);
2069    
2070                                    if (count.intValue() > 0) {
2071                                            return true;
2072                                    }
2073                            }
2074    
2075                            return false;
2076                    }
2077    
2078                    private MappingSqlQuery<Integer> _mappingSqlQuery;
2079            }
2080    
2081            protected class AddUser {
2082                    protected AddUser(TeamPersistenceImpl persistenceImpl) {
2083                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2084                                            "INSERT INTO Users_Teams (teamId, userId) VALUES (?, ?)",
2085                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2086                            _persistenceImpl = persistenceImpl;
2087                    }
2088    
2089                    protected void add(long teamId, long userId) throws SystemException {
2090                            if (!_persistenceImpl.containsUser.contains(teamId, userId)) {
2091                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2092    
2093                                    for (ModelListener<Team> listener : listeners) {
2094                                            listener.onBeforeAddAssociation(teamId,
2095                                                    com.liferay.portal.model.User.class.getName(), userId);
2096                                    }
2097    
2098                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2099                                            listener.onBeforeAddAssociation(userId,
2100                                                    Team.class.getName(), teamId);
2101                                    }
2102    
2103                                    _sqlUpdate.update(new Object[] {
2104                                                    new Long(teamId), new Long(userId)
2105                                            });
2106    
2107                                    for (ModelListener<Team> listener : listeners) {
2108                                            listener.onAfterAddAssociation(teamId,
2109                                                    com.liferay.portal.model.User.class.getName(), userId);
2110                                    }
2111    
2112                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2113                                            listener.onAfterAddAssociation(userId,
2114                                                    Team.class.getName(), teamId);
2115                                    }
2116                            }
2117                    }
2118    
2119                    private SqlUpdate _sqlUpdate;
2120                    private TeamPersistenceImpl _persistenceImpl;
2121            }
2122    
2123            protected class ClearUsers {
2124                    protected ClearUsers(TeamPersistenceImpl persistenceImpl) {
2125                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2126                                            "DELETE FROM Users_Teams WHERE teamId = ?",
2127                                            new int[] { java.sql.Types.BIGINT });
2128                    }
2129    
2130                    protected void clear(long teamId) throws SystemException {
2131                            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2132    
2133                            List<com.liferay.portal.model.User> users = null;
2134    
2135                            if ((listeners.length > 0) || (userListeners.length > 0)) {
2136                                    users = getUsers(teamId);
2137    
2138                                    for (com.liferay.portal.model.User user : users) {
2139                                            for (ModelListener<Team> listener : listeners) {
2140                                                    listener.onBeforeRemoveAssociation(teamId,
2141                                                            com.liferay.portal.model.User.class.getName(),
2142                                                            user.getPrimaryKey());
2143                                            }
2144    
2145                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2146                                                    listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2147                                                            Team.class.getName(), teamId);
2148                                            }
2149                                    }
2150                            }
2151    
2152                            _sqlUpdate.update(new Object[] { new Long(teamId) });
2153    
2154                            if ((listeners.length > 0) || (userListeners.length > 0)) {
2155                                    for (com.liferay.portal.model.User user : users) {
2156                                            for (ModelListener<Team> listener : listeners) {
2157                                                    listener.onAfterRemoveAssociation(teamId,
2158                                                            com.liferay.portal.model.User.class.getName(),
2159                                                            user.getPrimaryKey());
2160                                            }
2161    
2162                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2163                                                    listener.onAfterRemoveAssociation(user.getPrimaryKey(),
2164                                                            Team.class.getName(), teamId);
2165                                            }
2166                                    }
2167                            }
2168                    }
2169    
2170                    private SqlUpdate _sqlUpdate;
2171            }
2172    
2173            protected class RemoveUser {
2174                    protected RemoveUser(TeamPersistenceImpl persistenceImpl) {
2175                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2176                                            "DELETE FROM Users_Teams WHERE teamId = ? AND userId = ?",
2177                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2178                            _persistenceImpl = persistenceImpl;
2179                    }
2180    
2181                    protected void remove(long teamId, long userId)
2182                            throws SystemException {
2183                            if (_persistenceImpl.containsUser.contains(teamId, userId)) {
2184                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2185    
2186                                    for (ModelListener<Team> listener : listeners) {
2187                                            listener.onBeforeRemoveAssociation(teamId,
2188                                                    com.liferay.portal.model.User.class.getName(), userId);
2189                                    }
2190    
2191                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2192                                            listener.onBeforeRemoveAssociation(userId,
2193                                                    Team.class.getName(), teamId);
2194                                    }
2195    
2196                                    _sqlUpdate.update(new Object[] {
2197                                                    new Long(teamId), new Long(userId)
2198                                            });
2199    
2200                                    for (ModelListener<Team> listener : listeners) {
2201                                            listener.onAfterRemoveAssociation(teamId,
2202                                                    com.liferay.portal.model.User.class.getName(), userId);
2203                                    }
2204    
2205                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2206                                            listener.onAfterRemoveAssociation(userId,
2207                                                    Team.class.getName(), teamId);
2208                                    }
2209                            }
2210                    }
2211    
2212                    private SqlUpdate _sqlUpdate;
2213                    private TeamPersistenceImpl _persistenceImpl;
2214            }
2215    
2216            private static final String _SQL_SELECT_TEAM = "SELECT team FROM Team team";
2217            private static final String _SQL_SELECT_TEAM_WHERE = "SELECT team FROM Team team WHERE ";
2218            private static final String _SQL_COUNT_TEAM = "SELECT COUNT(team) FROM Team team";
2219            private static final String _SQL_COUNT_TEAM_WHERE = "SELECT COUNT(team) FROM Team team WHERE ";
2220            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Teams ON (Users_Teams.userId = User_.userId) WHERE (Users_Teams.teamId = ?)";
2221            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Teams WHERE teamId = ?";
2222            private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Teams WHERE teamId = ? AND userId = ?";
2223            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "team.groupId = ?";
2224            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "team.groupId = ? AND ";
2225            private static final String _FINDER_COLUMN_G_N_NAME_1 = "team.name IS NULL";
2226            private static final String _FINDER_COLUMN_G_N_NAME_2 = "team.name = ?";
2227            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(team.name IS NULL OR team.name = ?)";
2228            private static final String _FILTER_SQL_SELECT_TEAM_WHERE = "SELECT DISTINCT {team.*} FROM Team team WHERE ";
2229            private static final String _FILTER_SQL_COUNT_TEAM_WHERE = "SELECT COUNT(DISTINCT team.teamId) AS COUNT_VALUE FROM Team team WHERE ";
2230            private static final String _FILTER_COLUMN_PK = "team.teamId";
2231            private static final String _FILTER_COLUMN_USERID = "team.userId";
2232            private static final String _FILTER_ENTITY_ALIAS = "team";
2233            private static final String _ORDER_BY_ENTITY_ALIAS = "team.";
2234            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Team exists with the primary key ";
2235            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Team exists with the key {";
2236            private static Log _log = LogFactoryUtil.getLog(TeamPersistenceImpl.class);
2237    }