001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchTeamException;
020    import com.liferay.portal.kernel.bean.BeanReference;
021    import com.liferay.portal.kernel.dao.orm.EntityCache;
022    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderCache;
024    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025    import com.liferay.portal.kernel.dao.orm.FinderPath;
026    import com.liferay.portal.kernel.dao.orm.Query;
027    import com.liferay.portal.kernel.dao.orm.QueryPos;
028    import com.liferay.portal.kernel.dao.orm.QueryUtil;
029    import com.liferay.portal.kernel.dao.orm.SQLQuery;
030    import com.liferay.portal.kernel.dao.orm.Session;
031    import com.liferay.portal.kernel.log.Log;
032    import com.liferay.portal.kernel.log.LogFactoryUtil;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.SetUtil;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.MVCCModel;
041    import com.liferay.portal.model.Team;
042    import com.liferay.portal.model.impl.TeamImpl;
043    import com.liferay.portal.model.impl.TeamModelImpl;
044    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
045    import com.liferay.portal.service.ServiceContext;
046    import com.liferay.portal.service.ServiceContextThreadLocal;
047    import com.liferay.portal.service.persistence.TeamPersistence;
048    import com.liferay.portal.service.persistence.UserGroupPersistence;
049    import com.liferay.portal.service.persistence.UserPersistence;
050    
051    import java.io.Serializable;
052    
053    import java.util.Collections;
054    import java.util.Date;
055    import java.util.HashMap;
056    import java.util.HashSet;
057    import java.util.Iterator;
058    import java.util.List;
059    import java.util.Map;
060    import java.util.Set;
061    
062    /**
063     * The persistence implementation for the team service.
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see TeamPersistence
071     * @see com.liferay.portal.service.persistence.TeamUtil
072     * @generated
073     */
074    @ProviderType
075    public class TeamPersistenceImpl extends BasePersistenceImpl<Team>
076            implements TeamPersistence {
077            /*
078             * NOTE FOR DEVELOPERS:
079             *
080             * 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.
081             */
082            public static final String FINDER_CLASS_NAME_ENTITY = TeamImpl.class.getName();
083            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List1";
085            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086                    ".List2";
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
088                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
091                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
093            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
094                            TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
097                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
099                            new String[] {
100                                    String.class.getName(),
101                                    
102                            Integer.class.getName(), Integer.class.getName(),
103                                    OrderByComparator.class.getName()
104                            });
105            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
106                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
108                            new String[] { String.class.getName() },
109                            TeamModelImpl.UUID_COLUMN_BITMASK |
110                            TeamModelImpl.NAME_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
112                            TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
114                            new String[] { String.class.getName() });
115    
116            /**
117             * Returns all the teams where uuid = &#63;.
118             *
119             * @param uuid the uuid
120             * @return the matching teams
121             */
122            @Override
123            public List<Team> findByUuid(String uuid) {
124                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125            }
126    
127            /**
128             * Returns a range of all the teams where uuid = &#63;.
129             *
130             * <p>
131             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
132             * </p>
133             *
134             * @param uuid the uuid
135             * @param start the lower bound of the range of teams
136             * @param end the upper bound of the range of teams (not inclusive)
137             * @return the range of matching teams
138             */
139            @Override
140            public List<Team> findByUuid(String uuid, int start, int end) {
141                    return findByUuid(uuid, start, end, null);
142            }
143    
144            /**
145             * Returns an ordered range of all the teams where uuid = &#63;.
146             *
147             * <p>
148             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
149             * </p>
150             *
151             * @param uuid the uuid
152             * @param start the lower bound of the range of teams
153             * @param end the upper bound of the range of teams (not inclusive)
154             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
155             * @return the ordered range of matching teams
156             */
157            @Override
158            public List<Team> findByUuid(String uuid, int start, int end,
159                    OrderByComparator<Team> orderByComparator) {
160                    return findByUuid(uuid, start, end, orderByComparator, true);
161            }
162    
163            /**
164             * Returns an ordered range of all the teams where uuid = &#63;.
165             *
166             * <p>
167             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
168             * </p>
169             *
170             * @param uuid the uuid
171             * @param start the lower bound of the range of teams
172             * @param end the upper bound of the range of teams (not inclusive)
173             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
174             * @param retrieveFromCache whether to retrieve from the finder cache
175             * @return the ordered range of matching teams
176             */
177            @Override
178            public List<Team> findByUuid(String uuid, int start, int end,
179                    OrderByComparator<Team> orderByComparator, boolean retrieveFromCache) {
180                    boolean pagination = true;
181                    FinderPath finderPath = null;
182                    Object[] finderArgs = null;
183    
184                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
185                                    (orderByComparator == null)) {
186                            pagination = false;
187                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
188                            finderArgs = new Object[] { uuid };
189                    }
190                    else {
191                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
192                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
193                    }
194    
195                    List<Team> list = null;
196    
197                    if (retrieveFromCache) {
198                            list = (List<Team>)finderCache.getResult(finderPath, finderArgs,
199                                            this);
200    
201                            if ((list != null) && !list.isEmpty()) {
202                                    for (Team team : list) {
203                                            if (!Validator.equals(uuid, team.getUuid())) {
204                                                    list = null;
205    
206                                                    break;
207                                            }
208                                    }
209                            }
210                    }
211    
212                    if (list == null) {
213                            StringBundler query = null;
214    
215                            if (orderByComparator != null) {
216                                    query = new StringBundler(3 +
217                                                    (orderByComparator.getOrderByFields().length * 3));
218                            }
219                            else {
220                                    query = new StringBundler(3);
221                            }
222    
223                            query.append(_SQL_SELECT_TEAM_WHERE);
224    
225                            boolean bindUuid = false;
226    
227                            if (uuid == null) {
228                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
229                            }
230                            else if (uuid.equals(StringPool.BLANK)) {
231                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
232                            }
233                            else {
234                                    bindUuid = true;
235    
236                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
237                            }
238    
239                            if (orderByComparator != null) {
240                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
241                                            orderByComparator);
242                            }
243                            else
244                             if (pagination) {
245                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
246                            }
247    
248                            String sql = query.toString();
249    
250                            Session session = null;
251    
252                            try {
253                                    session = openSession();
254    
255                                    Query q = session.createQuery(sql);
256    
257                                    QueryPos qPos = QueryPos.getInstance(q);
258    
259                                    if (bindUuid) {
260                                            qPos.add(uuid);
261                                    }
262    
263                                    if (!pagination) {
264                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
265                                                            end, false);
266    
267                                            Collections.sort(list);
268    
269                                            list = Collections.unmodifiableList(list);
270                                    }
271                                    else {
272                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
273                                                            end);
274                                    }
275    
276                                    cacheResult(list);
277    
278                                    finderCache.putResult(finderPath, finderArgs, list);
279                            }
280                            catch (Exception e) {
281                                    finderCache.removeResult(finderPath, finderArgs);
282    
283                                    throw processException(e);
284                            }
285                            finally {
286                                    closeSession(session);
287                            }
288                    }
289    
290                    return list;
291            }
292    
293            /**
294             * Returns the first team in the ordered set where uuid = &#63;.
295             *
296             * @param uuid the uuid
297             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
298             * @return the first matching team
299             * @throws NoSuchTeamException if a matching team could not be found
300             */
301            @Override
302            public Team findByUuid_First(String uuid,
303                    OrderByComparator<Team> orderByComparator) throws NoSuchTeamException {
304                    Team team = fetchByUuid_First(uuid, orderByComparator);
305    
306                    if (team != null) {
307                            return team;
308                    }
309    
310                    StringBundler msg = new StringBundler(4);
311    
312                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
313    
314                    msg.append("uuid=");
315                    msg.append(uuid);
316    
317                    msg.append(StringPool.CLOSE_CURLY_BRACE);
318    
319                    throw new NoSuchTeamException(msg.toString());
320            }
321    
322            /**
323             * Returns the first team in the ordered set where uuid = &#63;.
324             *
325             * @param uuid the uuid
326             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
327             * @return the first matching team, or <code>null</code> if a matching team could not be found
328             */
329            @Override
330            public Team fetchByUuid_First(String uuid,
331                    OrderByComparator<Team> orderByComparator) {
332                    List<Team> list = findByUuid(uuid, 0, 1, orderByComparator);
333    
334                    if (!list.isEmpty()) {
335                            return list.get(0);
336                    }
337    
338                    return null;
339            }
340    
341            /**
342             * Returns the last team in the ordered set where uuid = &#63;.
343             *
344             * @param uuid the uuid
345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
346             * @return the last matching team
347             * @throws NoSuchTeamException if a matching team could not be found
348             */
349            @Override
350            public Team findByUuid_Last(String uuid,
351                    OrderByComparator<Team> orderByComparator) throws NoSuchTeamException {
352                    Team team = fetchByUuid_Last(uuid, orderByComparator);
353    
354                    if (team != null) {
355                            return team;
356                    }
357    
358                    StringBundler msg = new StringBundler(4);
359    
360                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
361    
362                    msg.append("uuid=");
363                    msg.append(uuid);
364    
365                    msg.append(StringPool.CLOSE_CURLY_BRACE);
366    
367                    throw new NoSuchTeamException(msg.toString());
368            }
369    
370            /**
371             * Returns the last team in the ordered set where uuid = &#63;.
372             *
373             * @param uuid the uuid
374             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
375             * @return the last matching team, or <code>null</code> if a matching team could not be found
376             */
377            @Override
378            public Team fetchByUuid_Last(String uuid,
379                    OrderByComparator<Team> orderByComparator) {
380                    int count = countByUuid(uuid);
381    
382                    if (count == 0) {
383                            return null;
384                    }
385    
386                    List<Team> list = findByUuid(uuid, count - 1, count, orderByComparator);
387    
388                    if (!list.isEmpty()) {
389                            return list.get(0);
390                    }
391    
392                    return null;
393            }
394    
395            /**
396             * Returns the teams before and after the current team in the ordered set where uuid = &#63;.
397             *
398             * @param teamId the primary key of the current team
399             * @param uuid the uuid
400             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
401             * @return the previous, current, and next team
402             * @throws NoSuchTeamException if a team with the primary key could not be found
403             */
404            @Override
405            public Team[] findByUuid_PrevAndNext(long teamId, String uuid,
406                    OrderByComparator<Team> orderByComparator) throws NoSuchTeamException {
407                    Team team = findByPrimaryKey(teamId);
408    
409                    Session session = null;
410    
411                    try {
412                            session = openSession();
413    
414                            Team[] array = new TeamImpl[3];
415    
416                            array[0] = getByUuid_PrevAndNext(session, team, uuid,
417                                            orderByComparator, true);
418    
419                            array[1] = team;
420    
421                            array[2] = getByUuid_PrevAndNext(session, team, uuid,
422                                            orderByComparator, false);
423    
424                            return array;
425                    }
426                    catch (Exception e) {
427                            throw processException(e);
428                    }
429                    finally {
430                            closeSession(session);
431                    }
432            }
433    
434            protected Team getByUuid_PrevAndNext(Session session, Team team,
435                    String uuid, OrderByComparator<Team> orderByComparator, boolean previous) {
436                    StringBundler query = null;
437    
438                    if (orderByComparator != null) {
439                            query = new StringBundler(6 +
440                                            (orderByComparator.getOrderByFields().length * 6));
441                    }
442                    else {
443                            query = new StringBundler(3);
444                    }
445    
446                    query.append(_SQL_SELECT_TEAM_WHERE);
447    
448                    boolean bindUuid = false;
449    
450                    if (uuid == null) {
451                            query.append(_FINDER_COLUMN_UUID_UUID_1);
452                    }
453                    else if (uuid.equals(StringPool.BLANK)) {
454                            query.append(_FINDER_COLUMN_UUID_UUID_3);
455                    }
456                    else {
457                            bindUuid = true;
458    
459                            query.append(_FINDER_COLUMN_UUID_UUID_2);
460                    }
461    
462                    if (orderByComparator != null) {
463                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
464    
465                            if (orderByConditionFields.length > 0) {
466                                    query.append(WHERE_AND);
467                            }
468    
469                            for (int i = 0; i < orderByConditionFields.length; i++) {
470                                    query.append(_ORDER_BY_ENTITY_ALIAS);
471                                    query.append(orderByConditionFields[i]);
472    
473                                    if ((i + 1) < orderByConditionFields.length) {
474                                            if (orderByComparator.isAscending() ^ previous) {
475                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
476                                            }
477                                            else {
478                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
479                                            }
480                                    }
481                                    else {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(WHERE_GREATER_THAN);
484                                            }
485                                            else {
486                                                    query.append(WHERE_LESSER_THAN);
487                                            }
488                                    }
489                            }
490    
491                            query.append(ORDER_BY_CLAUSE);
492    
493                            String[] orderByFields = orderByComparator.getOrderByFields();
494    
495                            for (int i = 0; i < orderByFields.length; i++) {
496                                    query.append(_ORDER_BY_ENTITY_ALIAS);
497                                    query.append(orderByFields[i]);
498    
499                                    if ((i + 1) < orderByFields.length) {
500                                            if (orderByComparator.isAscending() ^ previous) {
501                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
502                                            }
503                                            else {
504                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
505                                            }
506                                    }
507                                    else {
508                                            if (orderByComparator.isAscending() ^ previous) {
509                                                    query.append(ORDER_BY_ASC);
510                                            }
511                                            else {
512                                                    query.append(ORDER_BY_DESC);
513                                            }
514                                    }
515                            }
516                    }
517                    else {
518                            query.append(TeamModelImpl.ORDER_BY_JPQL);
519                    }
520    
521                    String sql = query.toString();
522    
523                    Query q = session.createQuery(sql);
524    
525                    q.setFirstResult(0);
526                    q.setMaxResults(2);
527    
528                    QueryPos qPos = QueryPos.getInstance(q);
529    
530                    if (bindUuid) {
531                            qPos.add(uuid);
532                    }
533    
534                    if (orderByComparator != null) {
535                            Object[] values = orderByComparator.getOrderByConditionValues(team);
536    
537                            for (Object value : values) {
538                                    qPos.add(value);
539                            }
540                    }
541    
542                    List<Team> list = q.list();
543    
544                    if (list.size() == 2) {
545                            return list.get(1);
546                    }
547                    else {
548                            return null;
549                    }
550            }
551    
552            /**
553             * Removes all the teams where uuid = &#63; from the database.
554             *
555             * @param uuid the uuid
556             */
557            @Override
558            public void removeByUuid(String uuid) {
559                    for (Team team : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
560                                    null)) {
561                            remove(team);
562                    }
563            }
564    
565            /**
566             * Returns the number of teams where uuid = &#63;.
567             *
568             * @param uuid the uuid
569             * @return the number of matching teams
570             */
571            @Override
572            public int countByUuid(String uuid) {
573                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
574    
575                    Object[] finderArgs = new Object[] { uuid };
576    
577                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
578    
579                    if (count == null) {
580                            StringBundler query = new StringBundler(2);
581    
582                            query.append(_SQL_COUNT_TEAM_WHERE);
583    
584                            boolean bindUuid = false;
585    
586                            if (uuid == null) {
587                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
588                            }
589                            else if (uuid.equals(StringPool.BLANK)) {
590                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
591                            }
592                            else {
593                                    bindUuid = true;
594    
595                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
596                            }
597    
598                            String sql = query.toString();
599    
600                            Session session = null;
601    
602                            try {
603                                    session = openSession();
604    
605                                    Query q = session.createQuery(sql);
606    
607                                    QueryPos qPos = QueryPos.getInstance(q);
608    
609                                    if (bindUuid) {
610                                            qPos.add(uuid);
611                                    }
612    
613                                    count = (Long)q.uniqueResult();
614    
615                                    finderCache.putResult(finderPath, finderArgs, count);
616                            }
617                            catch (Exception e) {
618                                    finderCache.removeResult(finderPath, finderArgs);
619    
620                                    throw processException(e);
621                            }
622                            finally {
623                                    closeSession(session);
624                            }
625                    }
626    
627                    return count.intValue();
628            }
629    
630            private static final String _FINDER_COLUMN_UUID_UUID_1 = "team.uuid IS NULL";
631            private static final String _FINDER_COLUMN_UUID_UUID_2 = "team.uuid = ?";
632            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(team.uuid IS NULL OR team.uuid = '')";
633            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
634                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
635                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
636                            new String[] { String.class.getName(), Long.class.getName() },
637                            TeamModelImpl.UUID_COLUMN_BITMASK |
638                            TeamModelImpl.GROUPID_COLUMN_BITMASK);
639            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
640                            TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
641                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
642                            new String[] { String.class.getName(), Long.class.getName() });
643    
644            /**
645             * Returns the team where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchTeamException} if it could not be found.
646             *
647             * @param uuid the uuid
648             * @param groupId the group ID
649             * @return the matching team
650             * @throws NoSuchTeamException if a matching team could not be found
651             */
652            @Override
653            public Team findByUUID_G(String uuid, long groupId)
654                    throws NoSuchTeamException {
655                    Team team = fetchByUUID_G(uuid, groupId);
656    
657                    if (team == null) {
658                            StringBundler msg = new StringBundler(6);
659    
660                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
661    
662                            msg.append("uuid=");
663                            msg.append(uuid);
664    
665                            msg.append(", groupId=");
666                            msg.append(groupId);
667    
668                            msg.append(StringPool.CLOSE_CURLY_BRACE);
669    
670                            if (_log.isWarnEnabled()) {
671                                    _log.warn(msg.toString());
672                            }
673    
674                            throw new NoSuchTeamException(msg.toString());
675                    }
676    
677                    return team;
678            }
679    
680            /**
681             * Returns the team where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
682             *
683             * @param uuid the uuid
684             * @param groupId the group ID
685             * @return the matching team, or <code>null</code> if a matching team could not be found
686             */
687            @Override
688            public Team fetchByUUID_G(String uuid, long groupId) {
689                    return fetchByUUID_G(uuid, groupId, true);
690            }
691    
692            /**
693             * Returns the team where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
694             *
695             * @param uuid the uuid
696             * @param groupId the group ID
697             * @param retrieveFromCache whether to retrieve from the finder cache
698             * @return the matching team, or <code>null</code> if a matching team could not be found
699             */
700            @Override
701            public Team fetchByUUID_G(String uuid, long groupId,
702                    boolean retrieveFromCache) {
703                    Object[] finderArgs = new Object[] { uuid, groupId };
704    
705                    Object result = null;
706    
707                    if (retrieveFromCache) {
708                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
709                                            finderArgs, this);
710                    }
711    
712                    if (result instanceof Team) {
713                            Team team = (Team)result;
714    
715                            if (!Validator.equals(uuid, team.getUuid()) ||
716                                            (groupId != team.getGroupId())) {
717                                    result = null;
718                            }
719                    }
720    
721                    if (result == null) {
722                            StringBundler query = new StringBundler(4);
723    
724                            query.append(_SQL_SELECT_TEAM_WHERE);
725    
726                            boolean bindUuid = false;
727    
728                            if (uuid == null) {
729                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
730                            }
731                            else if (uuid.equals(StringPool.BLANK)) {
732                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
733                            }
734                            else {
735                                    bindUuid = true;
736    
737                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
738                            }
739    
740                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
741    
742                            String sql = query.toString();
743    
744                            Session session = null;
745    
746                            try {
747                                    session = openSession();
748    
749                                    Query q = session.createQuery(sql);
750    
751                                    QueryPos qPos = QueryPos.getInstance(q);
752    
753                                    if (bindUuid) {
754                                            qPos.add(uuid);
755                                    }
756    
757                                    qPos.add(groupId);
758    
759                                    List<Team> list = q.list();
760    
761                                    if (list.isEmpty()) {
762                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
763                                                    finderArgs, list);
764                                    }
765                                    else {
766                                            Team team = list.get(0);
767    
768                                            result = team;
769    
770                                            cacheResult(team);
771    
772                                            if ((team.getUuid() == null) ||
773                                                            !team.getUuid().equals(uuid) ||
774                                                            (team.getGroupId() != groupId)) {
775                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
776                                                            finderArgs, team);
777                                            }
778                                    }
779                            }
780                            catch (Exception e) {
781                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
782    
783                                    throw processException(e);
784                            }
785                            finally {
786                                    closeSession(session);
787                            }
788                    }
789    
790                    if (result instanceof List<?>) {
791                            return null;
792                    }
793                    else {
794                            return (Team)result;
795                    }
796            }
797    
798            /**
799             * Removes the team where uuid = &#63; and groupId = &#63; from the database.
800             *
801             * @param uuid the uuid
802             * @param groupId the group ID
803             * @return the team that was removed
804             */
805            @Override
806            public Team removeByUUID_G(String uuid, long groupId)
807                    throws NoSuchTeamException {
808                    Team team = findByUUID_G(uuid, groupId);
809    
810                    return remove(team);
811            }
812    
813            /**
814             * Returns the number of teams where uuid = &#63; and groupId = &#63;.
815             *
816             * @param uuid the uuid
817             * @param groupId the group ID
818             * @return the number of matching teams
819             */
820            @Override
821            public int countByUUID_G(String uuid, long groupId) {
822                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
823    
824                    Object[] finderArgs = new Object[] { uuid, groupId };
825    
826                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
827    
828                    if (count == null) {
829                            StringBundler query = new StringBundler(3);
830    
831                            query.append(_SQL_COUNT_TEAM_WHERE);
832    
833                            boolean bindUuid = false;
834    
835                            if (uuid == null) {
836                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
837                            }
838                            else if (uuid.equals(StringPool.BLANK)) {
839                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
840                            }
841                            else {
842                                    bindUuid = true;
843    
844                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
845                            }
846    
847                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
848    
849                            String sql = query.toString();
850    
851                            Session session = null;
852    
853                            try {
854                                    session = openSession();
855    
856                                    Query q = session.createQuery(sql);
857    
858                                    QueryPos qPos = QueryPos.getInstance(q);
859    
860                                    if (bindUuid) {
861                                            qPos.add(uuid);
862                                    }
863    
864                                    qPos.add(groupId);
865    
866                                    count = (Long)q.uniqueResult();
867    
868                                    finderCache.putResult(finderPath, finderArgs, count);
869                            }
870                            catch (Exception e) {
871                                    finderCache.removeResult(finderPath, finderArgs);
872    
873                                    throw processException(e);
874                            }
875                            finally {
876                                    closeSession(session);
877                            }
878                    }
879    
880                    return count.intValue();
881            }
882    
883            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "team.uuid IS NULL AND ";
884            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "team.uuid = ? AND ";
885            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(team.uuid IS NULL OR team.uuid = '') AND ";
886            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "team.groupId = ?";
887            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
888                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
889                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
890                            new String[] {
891                                    String.class.getName(), Long.class.getName(),
892                                    
893                            Integer.class.getName(), Integer.class.getName(),
894                                    OrderByComparator.class.getName()
895                            });
896            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
897                    new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
898                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
899                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
900                            new String[] { String.class.getName(), Long.class.getName() },
901                            TeamModelImpl.UUID_COLUMN_BITMASK |
902                            TeamModelImpl.COMPANYID_COLUMN_BITMASK |
903                            TeamModelImpl.NAME_COLUMN_BITMASK);
904            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
905                            TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
906                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
907                            new String[] { String.class.getName(), Long.class.getName() });
908    
909            /**
910             * Returns all the teams where uuid = &#63; and companyId = &#63;.
911             *
912             * @param uuid the uuid
913             * @param companyId the company ID
914             * @return the matching teams
915             */
916            @Override
917            public List<Team> findByUuid_C(String uuid, long companyId) {
918                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
919                            QueryUtil.ALL_POS, null);
920            }
921    
922            /**
923             * Returns a range of all the teams where uuid = &#63; and companyId = &#63;.
924             *
925             * <p>
926             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
927             * </p>
928             *
929             * @param uuid the uuid
930             * @param companyId the company ID
931             * @param start the lower bound of the range of teams
932             * @param end the upper bound of the range of teams (not inclusive)
933             * @return the range of matching teams
934             */
935            @Override
936            public List<Team> findByUuid_C(String uuid, long companyId, int start,
937                    int end) {
938                    return findByUuid_C(uuid, companyId, start, end, null);
939            }
940    
941            /**
942             * Returns an ordered range of all the teams where uuid = &#63; and companyId = &#63;.
943             *
944             * <p>
945             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
946             * </p>
947             *
948             * @param uuid the uuid
949             * @param companyId the company ID
950             * @param start the lower bound of the range of teams
951             * @param end the upper bound of the range of teams (not inclusive)
952             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
953             * @return the ordered range of matching teams
954             */
955            @Override
956            public List<Team> findByUuid_C(String uuid, long companyId, int start,
957                    int end, OrderByComparator<Team> orderByComparator) {
958                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
959            }
960    
961            /**
962             * Returns an ordered range of all the teams where uuid = &#63; and companyId = &#63;.
963             *
964             * <p>
965             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
966             * </p>
967             *
968             * @param uuid the uuid
969             * @param companyId the company ID
970             * @param start the lower bound of the range of teams
971             * @param end the upper bound of the range of teams (not inclusive)
972             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
973             * @param retrieveFromCache whether to retrieve from the finder cache
974             * @return the ordered range of matching teams
975             */
976            @Override
977            public List<Team> findByUuid_C(String uuid, long companyId, int start,
978                    int end, OrderByComparator<Team> orderByComparator,
979                    boolean retrieveFromCache) {
980                    boolean pagination = true;
981                    FinderPath finderPath = null;
982                    Object[] finderArgs = null;
983    
984                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
985                                    (orderByComparator == null)) {
986                            pagination = false;
987                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
988                            finderArgs = new Object[] { uuid, companyId };
989                    }
990                    else {
991                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
992                            finderArgs = new Object[] {
993                                            uuid, companyId,
994                                            
995                                            start, end, orderByComparator
996                                    };
997                    }
998    
999                    List<Team> list = null;
1000    
1001                    if (retrieveFromCache) {
1002                            list = (List<Team>)finderCache.getResult(finderPath, finderArgs,
1003                                            this);
1004    
1005                            if ((list != null) && !list.isEmpty()) {
1006                                    for (Team team : list) {
1007                                            if (!Validator.equals(uuid, team.getUuid()) ||
1008                                                            (companyId != team.getCompanyId())) {
1009                                                    list = null;
1010    
1011                                                    break;
1012                                            }
1013                                    }
1014                            }
1015                    }
1016    
1017                    if (list == null) {
1018                            StringBundler query = null;
1019    
1020                            if (orderByComparator != null) {
1021                                    query = new StringBundler(4 +
1022                                                    (orderByComparator.getOrderByFields().length * 3));
1023                            }
1024                            else {
1025                                    query = new StringBundler(4);
1026                            }
1027    
1028                            query.append(_SQL_SELECT_TEAM_WHERE);
1029    
1030                            boolean bindUuid = false;
1031    
1032                            if (uuid == null) {
1033                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1034                            }
1035                            else if (uuid.equals(StringPool.BLANK)) {
1036                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1037                            }
1038                            else {
1039                                    bindUuid = true;
1040    
1041                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1042                            }
1043    
1044                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1045    
1046                            if (orderByComparator != null) {
1047                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1048                                            orderByComparator);
1049                            }
1050                            else
1051                             if (pagination) {
1052                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
1053                            }
1054    
1055                            String sql = query.toString();
1056    
1057                            Session session = null;
1058    
1059                            try {
1060                                    session = openSession();
1061    
1062                                    Query q = session.createQuery(sql);
1063    
1064                                    QueryPos qPos = QueryPos.getInstance(q);
1065    
1066                                    if (bindUuid) {
1067                                            qPos.add(uuid);
1068                                    }
1069    
1070                                    qPos.add(companyId);
1071    
1072                                    if (!pagination) {
1073                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1074                                                            end, false);
1075    
1076                                            Collections.sort(list);
1077    
1078                                            list = Collections.unmodifiableList(list);
1079                                    }
1080                                    else {
1081                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1082                                                            end);
1083                                    }
1084    
1085                                    cacheResult(list);
1086    
1087                                    finderCache.putResult(finderPath, finderArgs, list);
1088                            }
1089                            catch (Exception e) {
1090                                    finderCache.removeResult(finderPath, finderArgs);
1091    
1092                                    throw processException(e);
1093                            }
1094                            finally {
1095                                    closeSession(session);
1096                            }
1097                    }
1098    
1099                    return list;
1100            }
1101    
1102            /**
1103             * Returns the first team in the ordered set where uuid = &#63; and companyId = &#63;.
1104             *
1105             * @param uuid the uuid
1106             * @param companyId the company ID
1107             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1108             * @return the first matching team
1109             * @throws NoSuchTeamException if a matching team could not be found
1110             */
1111            @Override
1112            public Team findByUuid_C_First(String uuid, long companyId,
1113                    OrderByComparator<Team> orderByComparator) throws NoSuchTeamException {
1114                    Team team = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1115    
1116                    if (team != null) {
1117                            return team;
1118                    }
1119    
1120                    StringBundler msg = new StringBundler(6);
1121    
1122                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1123    
1124                    msg.append("uuid=");
1125                    msg.append(uuid);
1126    
1127                    msg.append(", companyId=");
1128                    msg.append(companyId);
1129    
1130                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1131    
1132                    throw new NoSuchTeamException(msg.toString());
1133            }
1134    
1135            /**
1136             * Returns the first team in the ordered set where uuid = &#63; and companyId = &#63;.
1137             *
1138             * @param uuid the uuid
1139             * @param companyId the company ID
1140             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1141             * @return the first matching team, or <code>null</code> if a matching team could not be found
1142             */
1143            @Override
1144            public Team fetchByUuid_C_First(String uuid, long companyId,
1145                    OrderByComparator<Team> orderByComparator) {
1146                    List<Team> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1147    
1148                    if (!list.isEmpty()) {
1149                            return list.get(0);
1150                    }
1151    
1152                    return null;
1153            }
1154    
1155            /**
1156             * Returns the last team in the ordered set where uuid = &#63; and companyId = &#63;.
1157             *
1158             * @param uuid the uuid
1159             * @param companyId the company ID
1160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1161             * @return the last matching team
1162             * @throws NoSuchTeamException if a matching team could not be found
1163             */
1164            @Override
1165            public Team findByUuid_C_Last(String uuid, long companyId,
1166                    OrderByComparator<Team> orderByComparator) throws NoSuchTeamException {
1167                    Team team = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1168    
1169                    if (team != null) {
1170                            return team;
1171                    }
1172    
1173                    StringBundler msg = new StringBundler(6);
1174    
1175                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1176    
1177                    msg.append("uuid=");
1178                    msg.append(uuid);
1179    
1180                    msg.append(", companyId=");
1181                    msg.append(companyId);
1182    
1183                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1184    
1185                    throw new NoSuchTeamException(msg.toString());
1186            }
1187    
1188            /**
1189             * Returns the last team in the ordered set where uuid = &#63; and companyId = &#63;.
1190             *
1191             * @param uuid the uuid
1192             * @param companyId the company ID
1193             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1194             * @return the last matching team, or <code>null</code> if a matching team could not be found
1195             */
1196            @Override
1197            public Team fetchByUuid_C_Last(String uuid, long companyId,
1198                    OrderByComparator<Team> orderByComparator) {
1199                    int count = countByUuid_C(uuid, companyId);
1200    
1201                    if (count == 0) {
1202                            return null;
1203                    }
1204    
1205                    List<Team> list = findByUuid_C(uuid, companyId, count - 1, count,
1206                                    orderByComparator);
1207    
1208                    if (!list.isEmpty()) {
1209                            return list.get(0);
1210                    }
1211    
1212                    return null;
1213            }
1214    
1215            /**
1216             * Returns the teams before and after the current team in the ordered set where uuid = &#63; and companyId = &#63;.
1217             *
1218             * @param teamId the primary key of the current team
1219             * @param uuid the uuid
1220             * @param companyId the company ID
1221             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1222             * @return the previous, current, and next team
1223             * @throws NoSuchTeamException if a team with the primary key could not be found
1224             */
1225            @Override
1226            public Team[] findByUuid_C_PrevAndNext(long teamId, String uuid,
1227                    long companyId, OrderByComparator<Team> orderByComparator)
1228                    throws NoSuchTeamException {
1229                    Team team = findByPrimaryKey(teamId);
1230    
1231                    Session session = null;
1232    
1233                    try {
1234                            session = openSession();
1235    
1236                            Team[] array = new TeamImpl[3];
1237    
1238                            array[0] = getByUuid_C_PrevAndNext(session, team, uuid, companyId,
1239                                            orderByComparator, true);
1240    
1241                            array[1] = team;
1242    
1243                            array[2] = getByUuid_C_PrevAndNext(session, team, uuid, companyId,
1244                                            orderByComparator, false);
1245    
1246                            return array;
1247                    }
1248                    catch (Exception e) {
1249                            throw processException(e);
1250                    }
1251                    finally {
1252                            closeSession(session);
1253                    }
1254            }
1255    
1256            protected Team getByUuid_C_PrevAndNext(Session session, Team team,
1257                    String uuid, long companyId, OrderByComparator<Team> orderByComparator,
1258                    boolean previous) {
1259                    StringBundler query = null;
1260    
1261                    if (orderByComparator != null) {
1262                            query = new StringBundler(6 +
1263                                            (orderByComparator.getOrderByFields().length * 6));
1264                    }
1265                    else {
1266                            query = new StringBundler(3);
1267                    }
1268    
1269                    query.append(_SQL_SELECT_TEAM_WHERE);
1270    
1271                    boolean bindUuid = false;
1272    
1273                    if (uuid == null) {
1274                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1275                    }
1276                    else if (uuid.equals(StringPool.BLANK)) {
1277                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1278                    }
1279                    else {
1280                            bindUuid = true;
1281    
1282                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1283                    }
1284    
1285                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1286    
1287                    if (orderByComparator != null) {
1288                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1289    
1290                            if (orderByConditionFields.length > 0) {
1291                                    query.append(WHERE_AND);
1292                            }
1293    
1294                            for (int i = 0; i < orderByConditionFields.length; i++) {
1295                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1296                                    query.append(orderByConditionFields[i]);
1297    
1298                                    if ((i + 1) < orderByConditionFields.length) {
1299                                            if (orderByComparator.isAscending() ^ previous) {
1300                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1301                                            }
1302                                            else {
1303                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1304                                            }
1305                                    }
1306                                    else {
1307                                            if (orderByComparator.isAscending() ^ previous) {
1308                                                    query.append(WHERE_GREATER_THAN);
1309                                            }
1310                                            else {
1311                                                    query.append(WHERE_LESSER_THAN);
1312                                            }
1313                                    }
1314                            }
1315    
1316                            query.append(ORDER_BY_CLAUSE);
1317    
1318                            String[] orderByFields = orderByComparator.getOrderByFields();
1319    
1320                            for (int i = 0; i < orderByFields.length; i++) {
1321                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1322                                    query.append(orderByFields[i]);
1323    
1324                                    if ((i + 1) < orderByFields.length) {
1325                                            if (orderByComparator.isAscending() ^ previous) {
1326                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1327                                            }
1328                                            else {
1329                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1330                                            }
1331                                    }
1332                                    else {
1333                                            if (orderByComparator.isAscending() ^ previous) {
1334                                                    query.append(ORDER_BY_ASC);
1335                                            }
1336                                            else {
1337                                                    query.append(ORDER_BY_DESC);
1338                                            }
1339                                    }
1340                            }
1341                    }
1342                    else {
1343                            query.append(TeamModelImpl.ORDER_BY_JPQL);
1344                    }
1345    
1346                    String sql = query.toString();
1347    
1348                    Query q = session.createQuery(sql);
1349    
1350                    q.setFirstResult(0);
1351                    q.setMaxResults(2);
1352    
1353                    QueryPos qPos = QueryPos.getInstance(q);
1354    
1355                    if (bindUuid) {
1356                            qPos.add(uuid);
1357                    }
1358    
1359                    qPos.add(companyId);
1360    
1361                    if (orderByComparator != null) {
1362                            Object[] values = orderByComparator.getOrderByConditionValues(team);
1363    
1364                            for (Object value : values) {
1365                                    qPos.add(value);
1366                            }
1367                    }
1368    
1369                    List<Team> list = q.list();
1370    
1371                    if (list.size() == 2) {
1372                            return list.get(1);
1373                    }
1374                    else {
1375                            return null;
1376                    }
1377            }
1378    
1379            /**
1380             * Removes all the teams where uuid = &#63; and companyId = &#63; from the database.
1381             *
1382             * @param uuid the uuid
1383             * @param companyId the company ID
1384             */
1385            @Override
1386            public void removeByUuid_C(String uuid, long companyId) {
1387                    for (Team team : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1388                                    QueryUtil.ALL_POS, null)) {
1389                            remove(team);
1390                    }
1391            }
1392    
1393            /**
1394             * Returns the number of teams where uuid = &#63; and companyId = &#63;.
1395             *
1396             * @param uuid the uuid
1397             * @param companyId the company ID
1398             * @return the number of matching teams
1399             */
1400            @Override
1401            public int countByUuid_C(String uuid, long companyId) {
1402                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1403    
1404                    Object[] finderArgs = new Object[] { uuid, companyId };
1405    
1406                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1407    
1408                    if (count == null) {
1409                            StringBundler query = new StringBundler(3);
1410    
1411                            query.append(_SQL_COUNT_TEAM_WHERE);
1412    
1413                            boolean bindUuid = false;
1414    
1415                            if (uuid == null) {
1416                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1417                            }
1418                            else if (uuid.equals(StringPool.BLANK)) {
1419                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1420                            }
1421                            else {
1422                                    bindUuid = true;
1423    
1424                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1425                            }
1426    
1427                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1428    
1429                            String sql = query.toString();
1430    
1431                            Session session = null;
1432    
1433                            try {
1434                                    session = openSession();
1435    
1436                                    Query q = session.createQuery(sql);
1437    
1438                                    QueryPos qPos = QueryPos.getInstance(q);
1439    
1440                                    if (bindUuid) {
1441                                            qPos.add(uuid);
1442                                    }
1443    
1444                                    qPos.add(companyId);
1445    
1446                                    count = (Long)q.uniqueResult();
1447    
1448                                    finderCache.putResult(finderPath, finderArgs, count);
1449                            }
1450                            catch (Exception e) {
1451                                    finderCache.removeResult(finderPath, finderArgs);
1452    
1453                                    throw processException(e);
1454                            }
1455                            finally {
1456                                    closeSession(session);
1457                            }
1458                    }
1459    
1460                    return count.intValue();
1461            }
1462    
1463            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "team.uuid IS NULL AND ";
1464            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "team.uuid = ? AND ";
1465            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(team.uuid IS NULL OR team.uuid = '') AND ";
1466            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "team.companyId = ?";
1467            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
1468                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
1469                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1470                            new String[] {
1471                                    Long.class.getName(),
1472                                    
1473                            Integer.class.getName(), Integer.class.getName(),
1474                                    OrderByComparator.class.getName()
1475                            });
1476            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1477                    new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
1478                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
1479                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1480                            new String[] { Long.class.getName() },
1481                            TeamModelImpl.GROUPID_COLUMN_BITMASK |
1482                            TeamModelImpl.NAME_COLUMN_BITMASK);
1483            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
1484                            TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
1485                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1486                            new String[] { Long.class.getName() });
1487    
1488            /**
1489             * Returns all the teams where groupId = &#63;.
1490             *
1491             * @param groupId the group ID
1492             * @return the matching teams
1493             */
1494            @Override
1495            public List<Team> findByGroupId(long groupId) {
1496                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1497            }
1498    
1499            /**
1500             * Returns a range of all the teams where groupId = &#63;.
1501             *
1502             * <p>
1503             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1504             * </p>
1505             *
1506             * @param groupId the group ID
1507             * @param start the lower bound of the range of teams
1508             * @param end the upper bound of the range of teams (not inclusive)
1509             * @return the range of matching teams
1510             */
1511            @Override
1512            public List<Team> findByGroupId(long groupId, int start, int end) {
1513                    return findByGroupId(groupId, start, end, null);
1514            }
1515    
1516            /**
1517             * Returns an ordered range of all the teams where groupId = &#63;.
1518             *
1519             * <p>
1520             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1521             * </p>
1522             *
1523             * @param groupId the group ID
1524             * @param start the lower bound of the range of teams
1525             * @param end the upper bound of the range of teams (not inclusive)
1526             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1527             * @return the ordered range of matching teams
1528             */
1529            @Override
1530            public List<Team> findByGroupId(long groupId, int start, int end,
1531                    OrderByComparator<Team> orderByComparator) {
1532                    return findByGroupId(groupId, start, end, orderByComparator, true);
1533            }
1534    
1535            /**
1536             * Returns an ordered range of all the teams where groupId = &#63;.
1537             *
1538             * <p>
1539             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1540             * </p>
1541             *
1542             * @param groupId the group ID
1543             * @param start the lower bound of the range of teams
1544             * @param end the upper bound of the range of teams (not inclusive)
1545             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1546             * @param retrieveFromCache whether to retrieve from the finder cache
1547             * @return the ordered range of matching teams
1548             */
1549            @Override
1550            public List<Team> findByGroupId(long groupId, int start, int end,
1551                    OrderByComparator<Team> orderByComparator, boolean retrieveFromCache) {
1552                    boolean pagination = true;
1553                    FinderPath finderPath = null;
1554                    Object[] finderArgs = null;
1555    
1556                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1557                                    (orderByComparator == null)) {
1558                            pagination = false;
1559                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1560                            finderArgs = new Object[] { groupId };
1561                    }
1562                    else {
1563                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1564                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1565                    }
1566    
1567                    List<Team> list = null;
1568    
1569                    if (retrieveFromCache) {
1570                            list = (List<Team>)finderCache.getResult(finderPath, finderArgs,
1571                                            this);
1572    
1573                            if ((list != null) && !list.isEmpty()) {
1574                                    for (Team team : list) {
1575                                            if ((groupId != team.getGroupId())) {
1576                                                    list = null;
1577    
1578                                                    break;
1579                                            }
1580                                    }
1581                            }
1582                    }
1583    
1584                    if (list == null) {
1585                            StringBundler query = null;
1586    
1587                            if (orderByComparator != null) {
1588                                    query = new StringBundler(3 +
1589                                                    (orderByComparator.getOrderByFields().length * 3));
1590                            }
1591                            else {
1592                                    query = new StringBundler(3);
1593                            }
1594    
1595                            query.append(_SQL_SELECT_TEAM_WHERE);
1596    
1597                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1598    
1599                            if (orderByComparator != null) {
1600                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1601                                            orderByComparator);
1602                            }
1603                            else
1604                             if (pagination) {
1605                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
1606                            }
1607    
1608                            String sql = query.toString();
1609    
1610                            Session session = null;
1611    
1612                            try {
1613                                    session = openSession();
1614    
1615                                    Query q = session.createQuery(sql);
1616    
1617                                    QueryPos qPos = QueryPos.getInstance(q);
1618    
1619                                    qPos.add(groupId);
1620    
1621                                    if (!pagination) {
1622                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1623                                                            end, false);
1624    
1625                                            Collections.sort(list);
1626    
1627                                            list = Collections.unmodifiableList(list);
1628                                    }
1629                                    else {
1630                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
1631                                                            end);
1632                                    }
1633    
1634                                    cacheResult(list);
1635    
1636                                    finderCache.putResult(finderPath, finderArgs, list);
1637                            }
1638                            catch (Exception e) {
1639                                    finderCache.removeResult(finderPath, finderArgs);
1640    
1641                                    throw processException(e);
1642                            }
1643                            finally {
1644                                    closeSession(session);
1645                            }
1646                    }
1647    
1648                    return list;
1649            }
1650    
1651            /**
1652             * Returns the first team in the ordered set where groupId = &#63;.
1653             *
1654             * @param groupId the group ID
1655             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1656             * @return the first matching team
1657             * @throws NoSuchTeamException if a matching team could not be found
1658             */
1659            @Override
1660            public Team findByGroupId_First(long groupId,
1661                    OrderByComparator<Team> orderByComparator) throws NoSuchTeamException {
1662                    Team team = fetchByGroupId_First(groupId, orderByComparator);
1663    
1664                    if (team != null) {
1665                            return team;
1666                    }
1667    
1668                    StringBundler msg = new StringBundler(4);
1669    
1670                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1671    
1672                    msg.append("groupId=");
1673                    msg.append(groupId);
1674    
1675                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1676    
1677                    throw new NoSuchTeamException(msg.toString());
1678            }
1679    
1680            /**
1681             * Returns the first team in the ordered set where groupId = &#63;.
1682             *
1683             * @param groupId the group ID
1684             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1685             * @return the first matching team, or <code>null</code> if a matching team could not be found
1686             */
1687            @Override
1688            public Team fetchByGroupId_First(long groupId,
1689                    OrderByComparator<Team> orderByComparator) {
1690                    List<Team> list = findByGroupId(groupId, 0, 1, orderByComparator);
1691    
1692                    if (!list.isEmpty()) {
1693                            return list.get(0);
1694                    }
1695    
1696                    return null;
1697            }
1698    
1699            /**
1700             * Returns the last team in the ordered set where groupId = &#63;.
1701             *
1702             * @param groupId the group ID
1703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1704             * @return the last matching team
1705             * @throws NoSuchTeamException if a matching team could not be found
1706             */
1707            @Override
1708            public Team findByGroupId_Last(long groupId,
1709                    OrderByComparator<Team> orderByComparator) throws NoSuchTeamException {
1710                    Team team = fetchByGroupId_Last(groupId, orderByComparator);
1711    
1712                    if (team != null) {
1713                            return team;
1714                    }
1715    
1716                    StringBundler msg = new StringBundler(4);
1717    
1718                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1719    
1720                    msg.append("groupId=");
1721                    msg.append(groupId);
1722    
1723                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1724    
1725                    throw new NoSuchTeamException(msg.toString());
1726            }
1727    
1728            /**
1729             * Returns the last team in the ordered set where groupId = &#63;.
1730             *
1731             * @param groupId the group ID
1732             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1733             * @return the last matching team, or <code>null</code> if a matching team could not be found
1734             */
1735            @Override
1736            public Team fetchByGroupId_Last(long groupId,
1737                    OrderByComparator<Team> orderByComparator) {
1738                    int count = countByGroupId(groupId);
1739    
1740                    if (count == 0) {
1741                            return null;
1742                    }
1743    
1744                    List<Team> list = findByGroupId(groupId, count - 1, count,
1745                                    orderByComparator);
1746    
1747                    if (!list.isEmpty()) {
1748                            return list.get(0);
1749                    }
1750    
1751                    return null;
1752            }
1753    
1754            /**
1755             * Returns the teams before and after the current team in the ordered set where groupId = &#63;.
1756             *
1757             * @param teamId the primary key of the current team
1758             * @param groupId the group ID
1759             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1760             * @return the previous, current, and next team
1761             * @throws NoSuchTeamException if a team with the primary key could not be found
1762             */
1763            @Override
1764            public Team[] findByGroupId_PrevAndNext(long teamId, long groupId,
1765                    OrderByComparator<Team> orderByComparator) throws NoSuchTeamException {
1766                    Team team = findByPrimaryKey(teamId);
1767    
1768                    Session session = null;
1769    
1770                    try {
1771                            session = openSession();
1772    
1773                            Team[] array = new TeamImpl[3];
1774    
1775                            array[0] = getByGroupId_PrevAndNext(session, team, groupId,
1776                                            orderByComparator, true);
1777    
1778                            array[1] = team;
1779    
1780                            array[2] = getByGroupId_PrevAndNext(session, team, groupId,
1781                                            orderByComparator, false);
1782    
1783                            return array;
1784                    }
1785                    catch (Exception e) {
1786                            throw processException(e);
1787                    }
1788                    finally {
1789                            closeSession(session);
1790                    }
1791            }
1792    
1793            protected Team getByGroupId_PrevAndNext(Session session, Team team,
1794                    long groupId, OrderByComparator<Team> orderByComparator,
1795                    boolean previous) {
1796                    StringBundler query = null;
1797    
1798                    if (orderByComparator != null) {
1799                            query = new StringBundler(6 +
1800                                            (orderByComparator.getOrderByFields().length * 6));
1801                    }
1802                    else {
1803                            query = new StringBundler(3);
1804                    }
1805    
1806                    query.append(_SQL_SELECT_TEAM_WHERE);
1807    
1808                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1809    
1810                    if (orderByComparator != null) {
1811                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1812    
1813                            if (orderByConditionFields.length > 0) {
1814                                    query.append(WHERE_AND);
1815                            }
1816    
1817                            for (int i = 0; i < orderByConditionFields.length; i++) {
1818                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1819                                    query.append(orderByConditionFields[i]);
1820    
1821                                    if ((i + 1) < orderByConditionFields.length) {
1822                                            if (orderByComparator.isAscending() ^ previous) {
1823                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1824                                            }
1825                                            else {
1826                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1827                                            }
1828                                    }
1829                                    else {
1830                                            if (orderByComparator.isAscending() ^ previous) {
1831                                                    query.append(WHERE_GREATER_THAN);
1832                                            }
1833                                            else {
1834                                                    query.append(WHERE_LESSER_THAN);
1835                                            }
1836                                    }
1837                            }
1838    
1839                            query.append(ORDER_BY_CLAUSE);
1840    
1841                            String[] orderByFields = orderByComparator.getOrderByFields();
1842    
1843                            for (int i = 0; i < orderByFields.length; i++) {
1844                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1845                                    query.append(orderByFields[i]);
1846    
1847                                    if ((i + 1) < orderByFields.length) {
1848                                            if (orderByComparator.isAscending() ^ previous) {
1849                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1850                                            }
1851                                            else {
1852                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1853                                            }
1854                                    }
1855                                    else {
1856                                            if (orderByComparator.isAscending() ^ previous) {
1857                                                    query.append(ORDER_BY_ASC);
1858                                            }
1859                                            else {
1860                                                    query.append(ORDER_BY_DESC);
1861                                            }
1862                                    }
1863                            }
1864                    }
1865                    else {
1866                            query.append(TeamModelImpl.ORDER_BY_JPQL);
1867                    }
1868    
1869                    String sql = query.toString();
1870    
1871                    Query q = session.createQuery(sql);
1872    
1873                    q.setFirstResult(0);
1874                    q.setMaxResults(2);
1875    
1876                    QueryPos qPos = QueryPos.getInstance(q);
1877    
1878                    qPos.add(groupId);
1879    
1880                    if (orderByComparator != null) {
1881                            Object[] values = orderByComparator.getOrderByConditionValues(team);
1882    
1883                            for (Object value : values) {
1884                                    qPos.add(value);
1885                            }
1886                    }
1887    
1888                    List<Team> list = q.list();
1889    
1890                    if (list.size() == 2) {
1891                            return list.get(1);
1892                    }
1893                    else {
1894                            return null;
1895                    }
1896            }
1897    
1898            /**
1899             * Returns all the teams that the user has permission to view where groupId = &#63;.
1900             *
1901             * @param groupId the group ID
1902             * @return the matching teams that the user has permission to view
1903             */
1904            @Override
1905            public List<Team> filterFindByGroupId(long groupId) {
1906                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1907                            QueryUtil.ALL_POS, null);
1908            }
1909    
1910            /**
1911             * Returns a range of all the teams that the user has permission to view where groupId = &#63;.
1912             *
1913             * <p>
1914             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1915             * </p>
1916             *
1917             * @param groupId the group ID
1918             * @param start the lower bound of the range of teams
1919             * @param end the upper bound of the range of teams (not inclusive)
1920             * @return the range of matching teams that the user has permission to view
1921             */
1922            @Override
1923            public List<Team> filterFindByGroupId(long groupId, int start, int end) {
1924                    return filterFindByGroupId(groupId, start, end, null);
1925            }
1926    
1927            /**
1928             * Returns an ordered range of all the teams that the user has permissions to view where groupId = &#63;.
1929             *
1930             * <p>
1931             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1932             * </p>
1933             *
1934             * @param groupId the group ID
1935             * @param start the lower bound of the range of teams
1936             * @param end the upper bound of the range of teams (not inclusive)
1937             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1938             * @return the ordered range of matching teams that the user has permission to view
1939             */
1940            @Override
1941            public List<Team> filterFindByGroupId(long groupId, int start, int end,
1942                    OrderByComparator<Team> orderByComparator) {
1943                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1944                            return findByGroupId(groupId, start, end, orderByComparator);
1945                    }
1946    
1947                    StringBundler query = null;
1948    
1949                    if (orderByComparator != null) {
1950                            query = new StringBundler(3 +
1951                                            (orderByComparator.getOrderByFields().length * 3));
1952                    }
1953                    else {
1954                            query = new StringBundler(3);
1955                    }
1956    
1957                    if (getDB().isSupportsInlineDistinct()) {
1958                            query.append(_FILTER_SQL_SELECT_TEAM_WHERE);
1959                    }
1960                    else {
1961                            query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_1);
1962                    }
1963    
1964                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1965    
1966                    if (!getDB().isSupportsInlineDistinct()) {
1967                            query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_2);
1968                    }
1969    
1970                    if (orderByComparator != null) {
1971                            if (getDB().isSupportsInlineDistinct()) {
1972                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1973                                            orderByComparator, true);
1974                            }
1975                            else {
1976                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1977                                            orderByComparator, true);
1978                            }
1979                    }
1980                    else {
1981                            if (getDB().isSupportsInlineDistinct()) {
1982                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
1983                            }
1984                            else {
1985                                    query.append(TeamModelImpl.ORDER_BY_SQL);
1986                            }
1987                    }
1988    
1989                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1990                                    Team.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
1991                                    groupId);
1992    
1993                    Session session = null;
1994    
1995                    try {
1996                            session = openSession();
1997    
1998                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1999    
2000                            if (getDB().isSupportsInlineDistinct()) {
2001                                    q.addEntity(_FILTER_ENTITY_ALIAS, TeamImpl.class);
2002                            }
2003                            else {
2004                                    q.addEntity(_FILTER_ENTITY_TABLE, TeamImpl.class);
2005                            }
2006    
2007                            QueryPos qPos = QueryPos.getInstance(q);
2008    
2009                            qPos.add(groupId);
2010    
2011                            return (List<Team>)QueryUtil.list(q, getDialect(), start, end);
2012                    }
2013                    catch (Exception e) {
2014                            throw processException(e);
2015                    }
2016                    finally {
2017                            closeSession(session);
2018                    }
2019            }
2020    
2021            /**
2022             * Returns the teams before and after the current team in the ordered set of teams that the user has permission to view where groupId = &#63;.
2023             *
2024             * @param teamId the primary key of the current team
2025             * @param groupId the group ID
2026             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2027             * @return the previous, current, and next team
2028             * @throws NoSuchTeamException if a team with the primary key could not be found
2029             */
2030            @Override
2031            public Team[] filterFindByGroupId_PrevAndNext(long teamId, long groupId,
2032                    OrderByComparator<Team> orderByComparator) throws NoSuchTeamException {
2033                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2034                            return findByGroupId_PrevAndNext(teamId, groupId, orderByComparator);
2035                    }
2036    
2037                    Team team = findByPrimaryKey(teamId);
2038    
2039                    Session session = null;
2040    
2041                    try {
2042                            session = openSession();
2043    
2044                            Team[] array = new TeamImpl[3];
2045    
2046                            array[0] = filterGetByGroupId_PrevAndNext(session, team, groupId,
2047                                            orderByComparator, true);
2048    
2049                            array[1] = team;
2050    
2051                            array[2] = filterGetByGroupId_PrevAndNext(session, team, groupId,
2052                                            orderByComparator, false);
2053    
2054                            return array;
2055                    }
2056                    catch (Exception e) {
2057                            throw processException(e);
2058                    }
2059                    finally {
2060                            closeSession(session);
2061                    }
2062            }
2063    
2064            protected Team filterGetByGroupId_PrevAndNext(Session session, Team team,
2065                    long groupId, OrderByComparator<Team> orderByComparator,
2066                    boolean previous) {
2067                    StringBundler query = null;
2068    
2069                    if (orderByComparator != null) {
2070                            query = new StringBundler(6 +
2071                                            (orderByComparator.getOrderByFields().length * 6));
2072                    }
2073                    else {
2074                            query = new StringBundler(3);
2075                    }
2076    
2077                    if (getDB().isSupportsInlineDistinct()) {
2078                            query.append(_FILTER_SQL_SELECT_TEAM_WHERE);
2079                    }
2080                    else {
2081                            query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_1);
2082                    }
2083    
2084                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2085    
2086                    if (!getDB().isSupportsInlineDistinct()) {
2087                            query.append(_FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_2);
2088                    }
2089    
2090                    if (orderByComparator != null) {
2091                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2092    
2093                            if (orderByConditionFields.length > 0) {
2094                                    query.append(WHERE_AND);
2095                            }
2096    
2097                            for (int i = 0; i < orderByConditionFields.length; i++) {
2098                                    if (getDB().isSupportsInlineDistinct()) {
2099                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2100                                    }
2101                                    else {
2102                                            query.append(_ORDER_BY_ENTITY_TABLE);
2103                                    }
2104    
2105                                    query.append(orderByConditionFields[i]);
2106    
2107                                    if ((i + 1) < orderByConditionFields.length) {
2108                                            if (orderByComparator.isAscending() ^ previous) {
2109                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2110                                            }
2111                                            else {
2112                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2113                                            }
2114                                    }
2115                                    else {
2116                                            if (orderByComparator.isAscending() ^ previous) {
2117                                                    query.append(WHERE_GREATER_THAN);
2118                                            }
2119                                            else {
2120                                                    query.append(WHERE_LESSER_THAN);
2121                                            }
2122                                    }
2123                            }
2124    
2125                            query.append(ORDER_BY_CLAUSE);
2126    
2127                            String[] orderByFields = orderByComparator.getOrderByFields();
2128    
2129                            for (int i = 0; i < orderByFields.length; i++) {
2130                                    if (getDB().isSupportsInlineDistinct()) {
2131                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2132                                    }
2133                                    else {
2134                                            query.append(_ORDER_BY_ENTITY_TABLE);
2135                                    }
2136    
2137                                    query.append(orderByFields[i]);
2138    
2139                                    if ((i + 1) < orderByFields.length) {
2140                                            if (orderByComparator.isAscending() ^ previous) {
2141                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2142                                            }
2143                                            else {
2144                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2145                                            }
2146                                    }
2147                                    else {
2148                                            if (orderByComparator.isAscending() ^ previous) {
2149                                                    query.append(ORDER_BY_ASC);
2150                                            }
2151                                            else {
2152                                                    query.append(ORDER_BY_DESC);
2153                                            }
2154                                    }
2155                            }
2156                    }
2157                    else {
2158                            if (getDB().isSupportsInlineDistinct()) {
2159                                    query.append(TeamModelImpl.ORDER_BY_JPQL);
2160                            }
2161                            else {
2162                                    query.append(TeamModelImpl.ORDER_BY_SQL);
2163                            }
2164                    }
2165    
2166                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2167                                    Team.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
2168                                    groupId);
2169    
2170                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2171    
2172                    q.setFirstResult(0);
2173                    q.setMaxResults(2);
2174    
2175                    if (getDB().isSupportsInlineDistinct()) {
2176                            q.addEntity(_FILTER_ENTITY_ALIAS, TeamImpl.class);
2177                    }
2178                    else {
2179                            q.addEntity(_FILTER_ENTITY_TABLE, TeamImpl.class);
2180                    }
2181    
2182                    QueryPos qPos = QueryPos.getInstance(q);
2183    
2184                    qPos.add(groupId);
2185    
2186                    if (orderByComparator != null) {
2187                            Object[] values = orderByComparator.getOrderByConditionValues(team);
2188    
2189                            for (Object value : values) {
2190                                    qPos.add(value);
2191                            }
2192                    }
2193    
2194                    List<Team> list = q.list();
2195    
2196                    if (list.size() == 2) {
2197                            return list.get(1);
2198                    }
2199                    else {
2200                            return null;
2201                    }
2202            }
2203    
2204            /**
2205             * Removes all the teams where groupId = &#63; from the database.
2206             *
2207             * @param groupId the group ID
2208             */
2209            @Override
2210            public void removeByGroupId(long groupId) {
2211                    for (Team team : findByGroupId(groupId, QueryUtil.ALL_POS,
2212                                    QueryUtil.ALL_POS, null)) {
2213                            remove(team);
2214                    }
2215            }
2216    
2217            /**
2218             * Returns the number of teams where groupId = &#63;.
2219             *
2220             * @param groupId the group ID
2221             * @return the number of matching teams
2222             */
2223            @Override
2224            public int countByGroupId(long groupId) {
2225                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2226    
2227                    Object[] finderArgs = new Object[] { groupId };
2228    
2229                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2230    
2231                    if (count == null) {
2232                            StringBundler query = new StringBundler(2);
2233    
2234                            query.append(_SQL_COUNT_TEAM_WHERE);
2235    
2236                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2237    
2238                            String sql = query.toString();
2239    
2240                            Session session = null;
2241    
2242                            try {
2243                                    session = openSession();
2244    
2245                                    Query q = session.createQuery(sql);
2246    
2247                                    QueryPos qPos = QueryPos.getInstance(q);
2248    
2249                                    qPos.add(groupId);
2250    
2251                                    count = (Long)q.uniqueResult();
2252    
2253                                    finderCache.putResult(finderPath, finderArgs, count);
2254                            }
2255                            catch (Exception e) {
2256                                    finderCache.removeResult(finderPath, finderArgs);
2257    
2258                                    throw processException(e);
2259                            }
2260                            finally {
2261                                    closeSession(session);
2262                            }
2263                    }
2264    
2265                    return count.intValue();
2266            }
2267    
2268            /**
2269             * Returns the number of teams that the user has permission to view where groupId = &#63;.
2270             *
2271             * @param groupId the group ID
2272             * @return the number of matching teams that the user has permission to view
2273             */
2274            @Override
2275            public int filterCountByGroupId(long groupId) {
2276                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2277                            return countByGroupId(groupId);
2278                    }
2279    
2280                    StringBundler query = new StringBundler(2);
2281    
2282                    query.append(_FILTER_SQL_COUNT_TEAM_WHERE);
2283    
2284                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2285    
2286                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2287                                    Team.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN,
2288                                    groupId);
2289    
2290                    Session session = null;
2291    
2292                    try {
2293                            session = openSession();
2294    
2295                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2296    
2297                            q.addScalar(COUNT_COLUMN_NAME,
2298                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2299    
2300                            QueryPos qPos = QueryPos.getInstance(q);
2301    
2302                            qPos.add(groupId);
2303    
2304                            Long count = (Long)q.uniqueResult();
2305    
2306                            return count.intValue();
2307                    }
2308                    catch (Exception e) {
2309                            throw processException(e);
2310                    }
2311                    finally {
2312                            closeSession(session);
2313                    }
2314            }
2315    
2316            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "team.groupId = ?";
2317            public static final FinderPath FINDER_PATH_FETCH_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
2318                            TeamModelImpl.FINDER_CACHE_ENABLED, TeamImpl.class,
2319                            FINDER_CLASS_NAME_ENTITY, "fetchByG_N",
2320                            new String[] { Long.class.getName(), String.class.getName() },
2321                            TeamModelImpl.GROUPID_COLUMN_BITMASK |
2322                            TeamModelImpl.NAME_COLUMN_BITMASK);
2323            public static final FinderPath FINDER_PATH_COUNT_BY_G_N = new FinderPath(TeamModelImpl.ENTITY_CACHE_ENABLED,
2324                            TeamModelImpl.FINDER_CACHE_ENABLED, Long.class,
2325                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_N",
2326                            new String[] { Long.class.getName(), String.class.getName() });
2327    
2328            /**
2329             * Returns the team where groupId = &#63; and name = &#63; or throws a {@link NoSuchTeamException} if it could not be found.
2330             *
2331             * @param groupId the group ID
2332             * @param name the name
2333             * @return the matching team
2334             * @throws NoSuchTeamException if a matching team could not be found
2335             */
2336            @Override
2337            public Team findByG_N(long groupId, String name) throws NoSuchTeamException {
2338                    Team team = fetchByG_N(groupId, name);
2339    
2340                    if (team == null) {
2341                            StringBundler msg = new StringBundler(6);
2342    
2343                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2344    
2345                            msg.append("groupId=");
2346                            msg.append(groupId);
2347    
2348                            msg.append(", name=");
2349                            msg.append(name);
2350    
2351                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2352    
2353                            if (_log.isWarnEnabled()) {
2354                                    _log.warn(msg.toString());
2355                            }
2356    
2357                            throw new NoSuchTeamException(msg.toString());
2358                    }
2359    
2360                    return team;
2361            }
2362    
2363            /**
2364             * Returns the team where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2365             *
2366             * @param groupId the group ID
2367             * @param name the name
2368             * @return the matching team, or <code>null</code> if a matching team could not be found
2369             */
2370            @Override
2371            public Team fetchByG_N(long groupId, String name) {
2372                    return fetchByG_N(groupId, name, true);
2373            }
2374    
2375            /**
2376             * Returns the team where groupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2377             *
2378             * @param groupId the group ID
2379             * @param name the name
2380             * @param retrieveFromCache whether to retrieve from the finder cache
2381             * @return the matching team, or <code>null</code> if a matching team could not be found
2382             */
2383            @Override
2384            public Team fetchByG_N(long groupId, String name, boolean retrieveFromCache) {
2385                    Object[] finderArgs = new Object[] { groupId, name };
2386    
2387                    Object result = null;
2388    
2389                    if (retrieveFromCache) {
2390                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_N,
2391                                            finderArgs, this);
2392                    }
2393    
2394                    if (result instanceof Team) {
2395                            Team team = (Team)result;
2396    
2397                            if ((groupId != team.getGroupId()) ||
2398                                            !Validator.equals(name, team.getName())) {
2399                                    result = null;
2400                            }
2401                    }
2402    
2403                    if (result == null) {
2404                            StringBundler query = new StringBundler(4);
2405    
2406                            query.append(_SQL_SELECT_TEAM_WHERE);
2407    
2408                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2409    
2410                            boolean bindName = false;
2411    
2412                            if (name == null) {
2413                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
2414                            }
2415                            else if (name.equals(StringPool.BLANK)) {
2416                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
2417                            }
2418                            else {
2419                                    bindName = true;
2420    
2421                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
2422                            }
2423    
2424                            String sql = query.toString();
2425    
2426                            Session session = null;
2427    
2428                            try {
2429                                    session = openSession();
2430    
2431                                    Query q = session.createQuery(sql);
2432    
2433                                    QueryPos qPos = QueryPos.getInstance(q);
2434    
2435                                    qPos.add(groupId);
2436    
2437                                    if (bindName) {
2438                                            qPos.add(name);
2439                                    }
2440    
2441                                    List<Team> list = q.list();
2442    
2443                                    if (list.isEmpty()) {
2444                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_N, finderArgs,
2445                                                    list);
2446                                    }
2447                                    else {
2448                                            Team team = list.get(0);
2449    
2450                                            result = team;
2451    
2452                                            cacheResult(team);
2453    
2454                                            if ((team.getGroupId() != groupId) ||
2455                                                            (team.getName() == null) ||
2456                                                            !team.getName().equals(name)) {
2457                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_N,
2458                                                            finderArgs, team);
2459                                            }
2460                                    }
2461                            }
2462                            catch (Exception e) {
2463                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_N, finderArgs);
2464    
2465                                    throw processException(e);
2466                            }
2467                            finally {
2468                                    closeSession(session);
2469                            }
2470                    }
2471    
2472                    if (result instanceof List<?>) {
2473                            return null;
2474                    }
2475                    else {
2476                            return (Team)result;
2477                    }
2478            }
2479    
2480            /**
2481             * Removes the team where groupId = &#63; and name = &#63; from the database.
2482             *
2483             * @param groupId the group ID
2484             * @param name the name
2485             * @return the team that was removed
2486             */
2487            @Override
2488            public Team removeByG_N(long groupId, String name)
2489                    throws NoSuchTeamException {
2490                    Team team = findByG_N(groupId, name);
2491    
2492                    return remove(team);
2493            }
2494    
2495            /**
2496             * Returns the number of teams where groupId = &#63; and name = &#63;.
2497             *
2498             * @param groupId the group ID
2499             * @param name the name
2500             * @return the number of matching teams
2501             */
2502            @Override
2503            public int countByG_N(long groupId, String name) {
2504                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_N;
2505    
2506                    Object[] finderArgs = new Object[] { groupId, name };
2507    
2508                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2509    
2510                    if (count == null) {
2511                            StringBundler query = new StringBundler(3);
2512    
2513                            query.append(_SQL_COUNT_TEAM_WHERE);
2514    
2515                            query.append(_FINDER_COLUMN_G_N_GROUPID_2);
2516    
2517                            boolean bindName = false;
2518    
2519                            if (name == null) {
2520                                    query.append(_FINDER_COLUMN_G_N_NAME_1);
2521                            }
2522                            else if (name.equals(StringPool.BLANK)) {
2523                                    query.append(_FINDER_COLUMN_G_N_NAME_3);
2524                            }
2525                            else {
2526                                    bindName = true;
2527    
2528                                    query.append(_FINDER_COLUMN_G_N_NAME_2);
2529                            }
2530    
2531                            String sql = query.toString();
2532    
2533                            Session session = null;
2534    
2535                            try {
2536                                    session = openSession();
2537    
2538                                    Query q = session.createQuery(sql);
2539    
2540                                    QueryPos qPos = QueryPos.getInstance(q);
2541    
2542                                    qPos.add(groupId);
2543    
2544                                    if (bindName) {
2545                                            qPos.add(name);
2546                                    }
2547    
2548                                    count = (Long)q.uniqueResult();
2549    
2550                                    finderCache.putResult(finderPath, finderArgs, count);
2551                            }
2552                            catch (Exception e) {
2553                                    finderCache.removeResult(finderPath, finderArgs);
2554    
2555                                    throw processException(e);
2556                            }
2557                            finally {
2558                                    closeSession(session);
2559                            }
2560                    }
2561    
2562                    return count.intValue();
2563            }
2564    
2565            private static final String _FINDER_COLUMN_G_N_GROUPID_2 = "team.groupId = ? AND ";
2566            private static final String _FINDER_COLUMN_G_N_NAME_1 = "team.name IS NULL";
2567            private static final String _FINDER_COLUMN_G_N_NAME_2 = "team.name = ?";
2568            private static final String _FINDER_COLUMN_G_N_NAME_3 = "(team.name IS NULL OR team.name = '')";
2569    
2570            public TeamPersistenceImpl() {
2571                    setModelClass(Team.class);
2572            }
2573    
2574            /**
2575             * Caches the team in the entity cache if it is enabled.
2576             *
2577             * @param team the team
2578             */
2579            @Override
2580            public void cacheResult(Team team) {
2581                    entityCache.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
2582                            TeamImpl.class, team.getPrimaryKey(), team);
2583    
2584                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2585                            new Object[] { team.getUuid(), team.getGroupId() }, team);
2586    
2587                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_N,
2588                            new Object[] { team.getGroupId(), team.getName() }, team);
2589    
2590                    team.resetOriginalValues();
2591            }
2592    
2593            /**
2594             * Caches the teams in the entity cache if it is enabled.
2595             *
2596             * @param teams the teams
2597             */
2598            @Override
2599            public void cacheResult(List<Team> teams) {
2600                    for (Team team : teams) {
2601                            if (entityCache.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
2602                                                    TeamImpl.class, team.getPrimaryKey()) == null) {
2603                                    cacheResult(team);
2604                            }
2605                            else {
2606                                    team.resetOriginalValues();
2607                            }
2608                    }
2609            }
2610    
2611            /**
2612             * Clears the cache for all teams.
2613             *
2614             * <p>
2615             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
2616             * </p>
2617             */
2618            @Override
2619            public void clearCache() {
2620                    entityCache.clearCache(TeamImpl.class);
2621    
2622                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
2623                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2624                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2625            }
2626    
2627            /**
2628             * Clears the cache for the team.
2629             *
2630             * <p>
2631             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
2632             * </p>
2633             */
2634            @Override
2635            public void clearCache(Team team) {
2636                    entityCache.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
2637                            TeamImpl.class, team.getPrimaryKey());
2638    
2639                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2640                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2641    
2642                    clearUniqueFindersCache((TeamModelImpl)team);
2643            }
2644    
2645            @Override
2646            public void clearCache(List<Team> teams) {
2647                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2648                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2649    
2650                    for (Team team : teams) {
2651                            entityCache.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
2652                                    TeamImpl.class, team.getPrimaryKey());
2653    
2654                            clearUniqueFindersCache((TeamModelImpl)team);
2655                    }
2656            }
2657    
2658            protected void cacheUniqueFindersCache(TeamModelImpl teamModelImpl,
2659                    boolean isNew) {
2660                    if (isNew) {
2661                            Object[] args = new Object[] {
2662                                            teamModelImpl.getUuid(), teamModelImpl.getGroupId()
2663                                    };
2664    
2665                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2666                                    Long.valueOf(1));
2667                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2668                                    teamModelImpl);
2669    
2670                            args = new Object[] {
2671                                            teamModelImpl.getGroupId(), teamModelImpl.getName()
2672                                    };
2673    
2674                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_N, args,
2675                                    Long.valueOf(1));
2676                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_N, args, teamModelImpl);
2677                    }
2678                    else {
2679                            if ((teamModelImpl.getColumnBitmask() &
2680                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2681                                    Object[] args = new Object[] {
2682                                                    teamModelImpl.getUuid(), teamModelImpl.getGroupId()
2683                                            };
2684    
2685                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2686                                            Long.valueOf(1));
2687                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2688                                            teamModelImpl);
2689                            }
2690    
2691                            if ((teamModelImpl.getColumnBitmask() &
2692                                            FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
2693                                    Object[] args = new Object[] {
2694                                                    teamModelImpl.getGroupId(), teamModelImpl.getName()
2695                                            };
2696    
2697                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_N, args,
2698                                            Long.valueOf(1));
2699                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_N, args,
2700                                            teamModelImpl);
2701                            }
2702                    }
2703            }
2704    
2705            protected void clearUniqueFindersCache(TeamModelImpl teamModelImpl) {
2706                    Object[] args = new Object[] {
2707                                    teamModelImpl.getUuid(), teamModelImpl.getGroupId()
2708                            };
2709    
2710                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2711                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2712    
2713                    if ((teamModelImpl.getColumnBitmask() &
2714                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2715                            args = new Object[] {
2716                                            teamModelImpl.getOriginalUuid(),
2717                                            teamModelImpl.getOriginalGroupId()
2718                                    };
2719    
2720                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2721                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2722                    }
2723    
2724                    args = new Object[] { teamModelImpl.getGroupId(), teamModelImpl.getName() };
2725    
2726                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
2727                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
2728    
2729                    if ((teamModelImpl.getColumnBitmask() &
2730                                    FINDER_PATH_FETCH_BY_G_N.getColumnBitmask()) != 0) {
2731                            args = new Object[] {
2732                                            teamModelImpl.getOriginalGroupId(),
2733                                            teamModelImpl.getOriginalName()
2734                                    };
2735    
2736                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_N, args);
2737                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_N, args);
2738                    }
2739            }
2740    
2741            /**
2742             * Creates a new team with the primary key. Does not add the team to the database.
2743             *
2744             * @param teamId the primary key for the new team
2745             * @return the new team
2746             */
2747            @Override
2748            public Team create(long teamId) {
2749                    Team team = new TeamImpl();
2750    
2751                    team.setNew(true);
2752                    team.setPrimaryKey(teamId);
2753    
2754                    String uuid = PortalUUIDUtil.generate();
2755    
2756                    team.setUuid(uuid);
2757    
2758                    return team;
2759            }
2760    
2761            /**
2762             * Removes the team with the primary key from the database. Also notifies the appropriate model listeners.
2763             *
2764             * @param teamId the primary key of the team
2765             * @return the team that was removed
2766             * @throws NoSuchTeamException if a team with the primary key could not be found
2767             */
2768            @Override
2769            public Team remove(long teamId) throws NoSuchTeamException {
2770                    return remove((Serializable)teamId);
2771            }
2772    
2773            /**
2774             * Removes the team with the primary key from the database. Also notifies the appropriate model listeners.
2775             *
2776             * @param primaryKey the primary key of the team
2777             * @return the team that was removed
2778             * @throws NoSuchTeamException if a team with the primary key could not be found
2779             */
2780            @Override
2781            public Team remove(Serializable primaryKey) throws NoSuchTeamException {
2782                    Session session = null;
2783    
2784                    try {
2785                            session = openSession();
2786    
2787                            Team team = (Team)session.get(TeamImpl.class, primaryKey);
2788    
2789                            if (team == null) {
2790                                    if (_log.isWarnEnabled()) {
2791                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2792                                    }
2793    
2794                                    throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2795                                            primaryKey);
2796                            }
2797    
2798                            return remove(team);
2799                    }
2800                    catch (NoSuchTeamException nsee) {
2801                            throw nsee;
2802                    }
2803                    catch (Exception e) {
2804                            throw processException(e);
2805                    }
2806                    finally {
2807                            closeSession(session);
2808                    }
2809            }
2810    
2811            @Override
2812            protected Team removeImpl(Team team) {
2813                    team = toUnwrappedModel(team);
2814    
2815                    teamToUserTableMapper.deleteLeftPrimaryKeyTableMappings(0,
2816                            team.getPrimaryKey());
2817    
2818                    teamToUserGroupTableMapper.deleteLeftPrimaryKeyTableMappings(0,
2819                            team.getPrimaryKey());
2820    
2821                    Session session = null;
2822    
2823                    try {
2824                            session = openSession();
2825    
2826                            if (!session.contains(team)) {
2827                                    team = (Team)session.get(TeamImpl.class, team.getPrimaryKeyObj());
2828                            }
2829    
2830                            if (team != null) {
2831                                    session.delete(team);
2832                            }
2833                    }
2834                    catch (Exception e) {
2835                            throw processException(e);
2836                    }
2837                    finally {
2838                            closeSession(session);
2839                    }
2840    
2841                    if (team != null) {
2842                            clearCache(team);
2843                    }
2844    
2845                    return team;
2846            }
2847    
2848            @Override
2849            public Team updateImpl(Team team) {
2850                    team = toUnwrappedModel(team);
2851    
2852                    boolean isNew = team.isNew();
2853    
2854                    TeamModelImpl teamModelImpl = (TeamModelImpl)team;
2855    
2856                    if (Validator.isNull(team.getUuid())) {
2857                            String uuid = PortalUUIDUtil.generate();
2858    
2859                            team.setUuid(uuid);
2860                    }
2861    
2862                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2863    
2864                    Date now = new Date();
2865    
2866                    if (isNew && (team.getCreateDate() == null)) {
2867                            if (serviceContext == null) {
2868                                    team.setCreateDate(now);
2869                            }
2870                            else {
2871                                    team.setCreateDate(serviceContext.getCreateDate(now));
2872                            }
2873                    }
2874    
2875                    if (!teamModelImpl.hasSetModifiedDate()) {
2876                            if (serviceContext == null) {
2877                                    team.setModifiedDate(now);
2878                            }
2879                            else {
2880                                    team.setModifiedDate(serviceContext.getModifiedDate(now));
2881                            }
2882                    }
2883    
2884                    Session session = null;
2885    
2886                    try {
2887                            session = openSession();
2888    
2889                            if (team.isNew()) {
2890                                    session.save(team);
2891    
2892                                    team.setNew(false);
2893                            }
2894                            else {
2895                                    team = (Team)session.merge(team);
2896                            }
2897                    }
2898                    catch (Exception e) {
2899                            throw processException(e);
2900                    }
2901                    finally {
2902                            closeSession(session);
2903                    }
2904    
2905                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2906    
2907                    if (isNew || !TeamModelImpl.COLUMN_BITMASK_ENABLED) {
2908                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2909                    }
2910    
2911                    else {
2912                            if ((teamModelImpl.getColumnBitmask() &
2913                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2914                                    Object[] args = new Object[] { teamModelImpl.getOriginalUuid() };
2915    
2916                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2917                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2918                                            args);
2919    
2920                                    args = new Object[] { teamModelImpl.getUuid() };
2921    
2922                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2923                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2924                                            args);
2925                            }
2926    
2927                            if ((teamModelImpl.getColumnBitmask() &
2928                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2929                                    Object[] args = new Object[] {
2930                                                    teamModelImpl.getOriginalUuid(),
2931                                                    teamModelImpl.getOriginalCompanyId()
2932                                            };
2933    
2934                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2935                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2936                                            args);
2937    
2938                                    args = new Object[] {
2939                                                    teamModelImpl.getUuid(), teamModelImpl.getCompanyId()
2940                                            };
2941    
2942                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2943                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2944                                            args);
2945                            }
2946    
2947                            if ((teamModelImpl.getColumnBitmask() &
2948                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2949                                    Object[] args = new Object[] { teamModelImpl.getOriginalGroupId() };
2950    
2951                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2952                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2953                                            args);
2954    
2955                                    args = new Object[] { teamModelImpl.getGroupId() };
2956    
2957                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2958                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2959                                            args);
2960                            }
2961                    }
2962    
2963                    entityCache.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
2964                            TeamImpl.class, team.getPrimaryKey(), team, false);
2965    
2966                    clearUniqueFindersCache(teamModelImpl);
2967                    cacheUniqueFindersCache(teamModelImpl, isNew);
2968    
2969                    team.resetOriginalValues();
2970    
2971                    return team;
2972            }
2973    
2974            protected Team toUnwrappedModel(Team team) {
2975                    if (team instanceof TeamImpl) {
2976                            return team;
2977                    }
2978    
2979                    TeamImpl teamImpl = new TeamImpl();
2980    
2981                    teamImpl.setNew(team.isNew());
2982                    teamImpl.setPrimaryKey(team.getPrimaryKey());
2983    
2984                    teamImpl.setMvccVersion(team.getMvccVersion());
2985                    teamImpl.setUuid(team.getUuid());
2986                    teamImpl.setTeamId(team.getTeamId());
2987                    teamImpl.setCompanyId(team.getCompanyId());
2988                    teamImpl.setUserId(team.getUserId());
2989                    teamImpl.setUserName(team.getUserName());
2990                    teamImpl.setCreateDate(team.getCreateDate());
2991                    teamImpl.setModifiedDate(team.getModifiedDate());
2992                    teamImpl.setGroupId(team.getGroupId());
2993                    teamImpl.setName(team.getName());
2994                    teamImpl.setDescription(team.getDescription());
2995                    teamImpl.setLastPublishDate(team.getLastPublishDate());
2996    
2997                    return teamImpl;
2998            }
2999    
3000            /**
3001             * Returns the team with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3002             *
3003             * @param primaryKey the primary key of the team
3004             * @return the team
3005             * @throws NoSuchTeamException if a team with the primary key could not be found
3006             */
3007            @Override
3008            public Team findByPrimaryKey(Serializable primaryKey)
3009                    throws NoSuchTeamException {
3010                    Team team = fetchByPrimaryKey(primaryKey);
3011    
3012                    if (team == null) {
3013                            if (_log.isWarnEnabled()) {
3014                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3015                            }
3016    
3017                            throw new NoSuchTeamException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3018                                    primaryKey);
3019                    }
3020    
3021                    return team;
3022            }
3023    
3024            /**
3025             * Returns the team with the primary key or throws a {@link NoSuchTeamException} if it could not be found.
3026             *
3027             * @param teamId the primary key of the team
3028             * @return the team
3029             * @throws NoSuchTeamException if a team with the primary key could not be found
3030             */
3031            @Override
3032            public Team findByPrimaryKey(long teamId) throws NoSuchTeamException {
3033                    return findByPrimaryKey((Serializable)teamId);
3034            }
3035    
3036            /**
3037             * Returns the team with the primary key or returns <code>null</code> if it could not be found.
3038             *
3039             * @param primaryKey the primary key of the team
3040             * @return the team, or <code>null</code> if a team with the primary key could not be found
3041             */
3042            @Override
3043            public Team fetchByPrimaryKey(Serializable primaryKey) {
3044                    Team team = (Team)entityCache.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
3045                                    TeamImpl.class, primaryKey);
3046    
3047                    if (team == _nullTeam) {
3048                            return null;
3049                    }
3050    
3051                    if (team == null) {
3052                            Session session = null;
3053    
3054                            try {
3055                                    session = openSession();
3056    
3057                                    team = (Team)session.get(TeamImpl.class, primaryKey);
3058    
3059                                    if (team != null) {
3060                                            cacheResult(team);
3061                                    }
3062                                    else {
3063                                            entityCache.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
3064                                                    TeamImpl.class, primaryKey, _nullTeam);
3065                                    }
3066                            }
3067                            catch (Exception e) {
3068                                    entityCache.removeResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
3069                                            TeamImpl.class, primaryKey);
3070    
3071                                    throw processException(e);
3072                            }
3073                            finally {
3074                                    closeSession(session);
3075                            }
3076                    }
3077    
3078                    return team;
3079            }
3080    
3081            /**
3082             * Returns the team with the primary key or returns <code>null</code> if it could not be found.
3083             *
3084             * @param teamId the primary key of the team
3085             * @return the team, or <code>null</code> if a team with the primary key could not be found
3086             */
3087            @Override
3088            public Team fetchByPrimaryKey(long teamId) {
3089                    return fetchByPrimaryKey((Serializable)teamId);
3090            }
3091    
3092            @Override
3093            public Map<Serializable, Team> fetchByPrimaryKeys(
3094                    Set<Serializable> primaryKeys) {
3095                    if (primaryKeys.isEmpty()) {
3096                            return Collections.emptyMap();
3097                    }
3098    
3099                    Map<Serializable, Team> map = new HashMap<Serializable, Team>();
3100    
3101                    if (primaryKeys.size() == 1) {
3102                            Iterator<Serializable> iterator = primaryKeys.iterator();
3103    
3104                            Serializable primaryKey = iterator.next();
3105    
3106                            Team team = fetchByPrimaryKey(primaryKey);
3107    
3108                            if (team != null) {
3109                                    map.put(primaryKey, team);
3110                            }
3111    
3112                            return map;
3113                    }
3114    
3115                    Set<Serializable> uncachedPrimaryKeys = null;
3116    
3117                    for (Serializable primaryKey : primaryKeys) {
3118                            Team team = (Team)entityCache.getResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
3119                                            TeamImpl.class, primaryKey);
3120    
3121                            if (team == null) {
3122                                    if (uncachedPrimaryKeys == null) {
3123                                            uncachedPrimaryKeys = new HashSet<Serializable>();
3124                                    }
3125    
3126                                    uncachedPrimaryKeys.add(primaryKey);
3127                            }
3128                            else {
3129                                    map.put(primaryKey, team);
3130                            }
3131                    }
3132    
3133                    if (uncachedPrimaryKeys == null) {
3134                            return map;
3135                    }
3136    
3137                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3138                                    1);
3139    
3140                    query.append(_SQL_SELECT_TEAM_WHERE_PKS_IN);
3141    
3142                    for (Serializable primaryKey : uncachedPrimaryKeys) {
3143                            query.append(String.valueOf(primaryKey));
3144    
3145                            query.append(StringPool.COMMA);
3146                    }
3147    
3148                    query.setIndex(query.index() - 1);
3149    
3150                    query.append(StringPool.CLOSE_PARENTHESIS);
3151    
3152                    String sql = query.toString();
3153    
3154                    Session session = null;
3155    
3156                    try {
3157                            session = openSession();
3158    
3159                            Query q = session.createQuery(sql);
3160    
3161                            for (Team team : (List<Team>)q.list()) {
3162                                    map.put(team.getPrimaryKeyObj(), team);
3163    
3164                                    cacheResult(team);
3165    
3166                                    uncachedPrimaryKeys.remove(team.getPrimaryKeyObj());
3167                            }
3168    
3169                            for (Serializable primaryKey : uncachedPrimaryKeys) {
3170                                    entityCache.putResult(TeamModelImpl.ENTITY_CACHE_ENABLED,
3171                                            TeamImpl.class, primaryKey, _nullTeam);
3172                            }
3173                    }
3174                    catch (Exception e) {
3175                            throw processException(e);
3176                    }
3177                    finally {
3178                            closeSession(session);
3179                    }
3180    
3181                    return map;
3182            }
3183    
3184            /**
3185             * Returns all the teams.
3186             *
3187             * @return the teams
3188             */
3189            @Override
3190            public List<Team> findAll() {
3191                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3192            }
3193    
3194            /**
3195             * Returns a range of all the teams.
3196             *
3197             * <p>
3198             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3199             * </p>
3200             *
3201             * @param start the lower bound of the range of teams
3202             * @param end the upper bound of the range of teams (not inclusive)
3203             * @return the range of teams
3204             */
3205            @Override
3206            public List<Team> findAll(int start, int end) {
3207                    return findAll(start, end, null);
3208            }
3209    
3210            /**
3211             * Returns an ordered range of all the teams.
3212             *
3213             * <p>
3214             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3215             * </p>
3216             *
3217             * @param start the lower bound of the range of teams
3218             * @param end the upper bound of the range of teams (not inclusive)
3219             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3220             * @return the ordered range of teams
3221             */
3222            @Override
3223            public List<Team> findAll(int start, int end,
3224                    OrderByComparator<Team> orderByComparator) {
3225                    return findAll(start, end, orderByComparator, true);
3226            }
3227    
3228            /**
3229             * Returns an ordered range of all the teams.
3230             *
3231             * <p>
3232             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3233             * </p>
3234             *
3235             * @param start the lower bound of the range of teams
3236             * @param end the upper bound of the range of teams (not inclusive)
3237             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3238             * @param retrieveFromCache whether to retrieve from the finder cache
3239             * @return the ordered range of teams
3240             */
3241            @Override
3242            public List<Team> findAll(int start, int end,
3243                    OrderByComparator<Team> orderByComparator, boolean retrieveFromCache) {
3244                    boolean pagination = true;
3245                    FinderPath finderPath = null;
3246                    Object[] finderArgs = null;
3247    
3248                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3249                                    (orderByComparator == null)) {
3250                            pagination = false;
3251                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3252                            finderArgs = FINDER_ARGS_EMPTY;
3253                    }
3254                    else {
3255                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3256                            finderArgs = new Object[] { start, end, orderByComparator };
3257                    }
3258    
3259                    List<Team> list = null;
3260    
3261                    if (retrieveFromCache) {
3262                            list = (List<Team>)finderCache.getResult(finderPath, finderArgs,
3263                                            this);
3264                    }
3265    
3266                    if (list == null) {
3267                            StringBundler query = null;
3268                            String sql = null;
3269    
3270                            if (orderByComparator != null) {
3271                                    query = new StringBundler(2 +
3272                                                    (orderByComparator.getOrderByFields().length * 3));
3273    
3274                                    query.append(_SQL_SELECT_TEAM);
3275    
3276                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3277                                            orderByComparator);
3278    
3279                                    sql = query.toString();
3280                            }
3281                            else {
3282                                    sql = _SQL_SELECT_TEAM;
3283    
3284                                    if (pagination) {
3285                                            sql = sql.concat(TeamModelImpl.ORDER_BY_JPQL);
3286                                    }
3287                            }
3288    
3289                            Session session = null;
3290    
3291                            try {
3292                                    session = openSession();
3293    
3294                                    Query q = session.createQuery(sql);
3295    
3296                                    if (!pagination) {
3297                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
3298                                                            end, false);
3299    
3300                                            Collections.sort(list);
3301    
3302                                            list = Collections.unmodifiableList(list);
3303                                    }
3304                                    else {
3305                                            list = (List<Team>)QueryUtil.list(q, getDialect(), start,
3306                                                            end);
3307                                    }
3308    
3309                                    cacheResult(list);
3310    
3311                                    finderCache.putResult(finderPath, finderArgs, list);
3312                            }
3313                            catch (Exception e) {
3314                                    finderCache.removeResult(finderPath, finderArgs);
3315    
3316                                    throw processException(e);
3317                            }
3318                            finally {
3319                                    closeSession(session);
3320                            }
3321                    }
3322    
3323                    return list;
3324            }
3325    
3326            /**
3327             * Removes all the teams from the database.
3328             *
3329             */
3330            @Override
3331            public void removeAll() {
3332                    for (Team team : findAll()) {
3333                            remove(team);
3334                    }
3335            }
3336    
3337            /**
3338             * Returns the number of teams.
3339             *
3340             * @return the number of teams
3341             */
3342            @Override
3343            public int countAll() {
3344                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3345                                    FINDER_ARGS_EMPTY, this);
3346    
3347                    if (count == null) {
3348                            Session session = null;
3349    
3350                            try {
3351                                    session = openSession();
3352    
3353                                    Query q = session.createQuery(_SQL_COUNT_TEAM);
3354    
3355                                    count = (Long)q.uniqueResult();
3356    
3357                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3358                                            count);
3359                            }
3360                            catch (Exception e) {
3361                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3362                                            FINDER_ARGS_EMPTY);
3363    
3364                                    throw processException(e);
3365                            }
3366                            finally {
3367                                    closeSession(session);
3368                            }
3369                    }
3370    
3371                    return count.intValue();
3372            }
3373    
3374            /**
3375             * Returns the primaryKeys of users associated with the team.
3376             *
3377             * @param pk the primary key of the team
3378             * @return long[] of the primaryKeys of users associated with the team
3379             */
3380            @Override
3381            public long[] getUserPrimaryKeys(long pk) {
3382                    long[] pks = teamToUserTableMapper.getRightPrimaryKeys(0, pk);
3383    
3384                    return pks.clone();
3385            }
3386    
3387            /**
3388             * Returns all the users associated with the team.
3389             *
3390             * @param pk the primary key of the team
3391             * @return the users associated with the team
3392             */
3393            @Override
3394            public List<com.liferay.portal.model.User> getUsers(long pk) {
3395                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3396            }
3397    
3398            /**
3399             * Returns a range of all the users associated with the team.
3400             *
3401             * <p>
3402             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3403             * </p>
3404             *
3405             * @param pk the primary key of the team
3406             * @param start the lower bound of the range of teams
3407             * @param end the upper bound of the range of teams (not inclusive)
3408             * @return the range of users associated with the team
3409             */
3410            @Override
3411            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3412                    int end) {
3413                    return getUsers(pk, start, end, null);
3414            }
3415    
3416            /**
3417             * Returns an ordered range of all the users associated with the team.
3418             *
3419             * <p>
3420             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3421             * </p>
3422             *
3423             * @param pk the primary key of the team
3424             * @param start the lower bound of the range of teams
3425             * @param end the upper bound of the range of teams (not inclusive)
3426             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3427             * @return the ordered range of users associated with the team
3428             */
3429            @Override
3430            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3431                    int end,
3432                    OrderByComparator<com.liferay.portal.model.User> orderByComparator) {
3433                    return teamToUserTableMapper.getRightBaseModels(0, pk, start, end,
3434                            orderByComparator);
3435            }
3436    
3437            /**
3438             * Returns the number of users associated with the team.
3439             *
3440             * @param pk the primary key of the team
3441             * @return the number of users associated with the team
3442             */
3443            @Override
3444            public int getUsersSize(long pk) {
3445                    long[] pks = teamToUserTableMapper.getRightPrimaryKeys(0, pk);
3446    
3447                    return pks.length;
3448            }
3449    
3450            /**
3451             * Returns <code>true</code> if the user is associated with the team.
3452             *
3453             * @param pk the primary key of the team
3454             * @param userPK the primary key of the user
3455             * @return <code>true</code> if the user is associated with the team; <code>false</code> otherwise
3456             */
3457            @Override
3458            public boolean containsUser(long pk, long userPK) {
3459                    return teamToUserTableMapper.containsTableMapping(0, pk, userPK);
3460            }
3461    
3462            /**
3463             * Returns <code>true</code> if the team has any users associated with it.
3464             *
3465             * @param pk the primary key of the team to check for associations with users
3466             * @return <code>true</code> if the team has any users associated with it; <code>false</code> otherwise
3467             */
3468            @Override
3469            public boolean containsUsers(long pk) {
3470                    if (getUsersSize(pk) > 0) {
3471                            return true;
3472                    }
3473                    else {
3474                            return false;
3475                    }
3476            }
3477    
3478            /**
3479             * Adds an association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3480             *
3481             * @param pk the primary key of the team
3482             * @param userPK the primary key of the user
3483             */
3484            @Override
3485            public void addUser(long pk, long userPK) {
3486                    teamToUserTableMapper.addTableMapping(0, pk, userPK);
3487            }
3488    
3489            /**
3490             * Adds an association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3491             *
3492             * @param pk the primary key of the team
3493             * @param user the user
3494             */
3495            @Override
3496            public void addUser(long pk, com.liferay.portal.model.User user) {
3497                    teamToUserTableMapper.addTableMapping(0, pk, user.getPrimaryKey());
3498            }
3499    
3500            /**
3501             * Adds an association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3502             *
3503             * @param pk the primary key of the team
3504             * @param userPKs the primary keys of the users
3505             */
3506            @Override
3507            public void addUsers(long pk, long[] userPKs) {
3508                    for (long userPK : userPKs) {
3509                            teamToUserTableMapper.addTableMapping(0, pk, userPK);
3510                    }
3511            }
3512    
3513            /**
3514             * Adds an association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3515             *
3516             * @param pk the primary key of the team
3517             * @param users the users
3518             */
3519            @Override
3520            public void addUsers(long pk, List<com.liferay.portal.model.User> users) {
3521                    for (com.liferay.portal.model.User user : users) {
3522                            teamToUserTableMapper.addTableMapping(0, pk, user.getPrimaryKey());
3523                    }
3524            }
3525    
3526            /**
3527             * Clears all associations between the team and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3528             *
3529             * @param pk the primary key of the team to clear the associated users from
3530             */
3531            @Override
3532            public void clearUsers(long pk) {
3533                    teamToUserTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
3534            }
3535    
3536            /**
3537             * Removes the association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3538             *
3539             * @param pk the primary key of the team
3540             * @param userPK the primary key of the user
3541             */
3542            @Override
3543            public void removeUser(long pk, long userPK) {
3544                    teamToUserTableMapper.deleteTableMapping(0, pk, userPK);
3545            }
3546    
3547            /**
3548             * Removes the association between the team and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3549             *
3550             * @param pk the primary key of the team
3551             * @param user the user
3552             */
3553            @Override
3554            public void removeUser(long pk, com.liferay.portal.model.User user) {
3555                    teamToUserTableMapper.deleteTableMapping(0, pk, user.getPrimaryKey());
3556            }
3557    
3558            /**
3559             * Removes the association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3560             *
3561             * @param pk the primary key of the team
3562             * @param userPKs the primary keys of the users
3563             */
3564            @Override
3565            public void removeUsers(long pk, long[] userPKs) {
3566                    for (long userPK : userPKs) {
3567                            teamToUserTableMapper.deleteTableMapping(0, pk, userPK);
3568                    }
3569            }
3570    
3571            /**
3572             * Removes the association between the team and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3573             *
3574             * @param pk the primary key of the team
3575             * @param users the users
3576             */
3577            @Override
3578            public void removeUsers(long pk, List<com.liferay.portal.model.User> users) {
3579                    for (com.liferay.portal.model.User user : users) {
3580                            teamToUserTableMapper.deleteTableMapping(0, pk, user.getPrimaryKey());
3581                    }
3582            }
3583    
3584            /**
3585             * 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.
3586             *
3587             * @param pk the primary key of the team
3588             * @param userPKs the primary keys of the users to be associated with the team
3589             */
3590            @Override
3591            public void setUsers(long pk, long[] userPKs) {
3592                    Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
3593                    Set<Long> oldUserPKsSet = SetUtil.fromArray(teamToUserTableMapper.getRightPrimaryKeys(
3594                                            0, pk));
3595    
3596                    Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
3597    
3598                    removeUserPKsSet.removeAll(newUserPKsSet);
3599    
3600                    for (long removeUserPK : removeUserPKsSet) {
3601                            teamToUserTableMapper.deleteTableMapping(0, pk, removeUserPK);
3602                    }
3603    
3604                    newUserPKsSet.removeAll(oldUserPKsSet);
3605    
3606                    for (long newUserPK : newUserPKsSet) {
3607                            teamToUserTableMapper.addTableMapping(0, pk, newUserPK);
3608                    }
3609            }
3610    
3611            /**
3612             * 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.
3613             *
3614             * @param pk the primary key of the team
3615             * @param users the users to be associated with the team
3616             */
3617            @Override
3618            public void setUsers(long pk, List<com.liferay.portal.model.User> users) {
3619                    try {
3620                            long[] userPKs = new long[users.size()];
3621    
3622                            for (int i = 0; i < users.size(); i++) {
3623                                    com.liferay.portal.model.User user = users.get(i);
3624    
3625                                    userPKs[i] = user.getPrimaryKey();
3626                            }
3627    
3628                            setUsers(pk, userPKs);
3629                    }
3630                    catch (Exception e) {
3631                            throw processException(e);
3632                    }
3633            }
3634    
3635            /**
3636             * Returns the primaryKeys of user groups associated with the team.
3637             *
3638             * @param pk the primary key of the team
3639             * @return long[] of the primaryKeys of user groups associated with the team
3640             */
3641            @Override
3642            public long[] getUserGroupPrimaryKeys(long pk) {
3643                    long[] pks = teamToUserGroupTableMapper.getRightPrimaryKeys(0, pk);
3644    
3645                    return pks.clone();
3646            }
3647    
3648            /**
3649             * Returns all the user groups associated with the team.
3650             *
3651             * @param pk the primary key of the team
3652             * @return the user groups associated with the team
3653             */
3654            @Override
3655            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk) {
3656                    return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3657            }
3658    
3659            /**
3660             * Returns a range of all the user groups associated with the team.
3661             *
3662             * <p>
3663             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3664             * </p>
3665             *
3666             * @param pk the primary key of the team
3667             * @param start the lower bound of the range of teams
3668             * @param end the upper bound of the range of teams (not inclusive)
3669             * @return the range of user groups associated with the team
3670             */
3671            @Override
3672            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
3673                    int start, int end) {
3674                    return getUserGroups(pk, start, end, null);
3675            }
3676    
3677            /**
3678             * Returns an ordered range of all the user groups associated with the team.
3679             *
3680             * <p>
3681             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link TeamModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3682             * </p>
3683             *
3684             * @param pk the primary key of the team
3685             * @param start the lower bound of the range of teams
3686             * @param end the upper bound of the range of teams (not inclusive)
3687             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3688             * @return the ordered range of user groups associated with the team
3689             */
3690            @Override
3691            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
3692                    int start, int end,
3693                    OrderByComparator<com.liferay.portal.model.UserGroup> orderByComparator) {
3694                    return teamToUserGroupTableMapper.getRightBaseModels(0, pk, start, end,
3695                            orderByComparator);
3696            }
3697    
3698            /**
3699             * Returns the number of user groups associated with the team.
3700             *
3701             * @param pk the primary key of the team
3702             * @return the number of user groups associated with the team
3703             */
3704            @Override
3705            public int getUserGroupsSize(long pk) {
3706                    long[] pks = teamToUserGroupTableMapper.getRightPrimaryKeys(0, pk);
3707    
3708                    return pks.length;
3709            }
3710    
3711            /**
3712             * Returns <code>true</code> if the user group is associated with the team.
3713             *
3714             * @param pk the primary key of the team
3715             * @param userGroupPK the primary key of the user group
3716             * @return <code>true</code> if the user group is associated with the team; <code>false</code> otherwise
3717             */
3718            @Override
3719            public boolean containsUserGroup(long pk, long userGroupPK) {
3720                    return teamToUserGroupTableMapper.containsTableMapping(0, pk,
3721                            userGroupPK);
3722            }
3723    
3724            /**
3725             * Returns <code>true</code> if the team has any user groups associated with it.
3726             *
3727             * @param pk the primary key of the team to check for associations with user groups
3728             * @return <code>true</code> if the team has any user groups associated with it; <code>false</code> otherwise
3729             */
3730            @Override
3731            public boolean containsUserGroups(long pk) {
3732                    if (getUserGroupsSize(pk) > 0) {
3733                            return true;
3734                    }
3735                    else {
3736                            return false;
3737                    }
3738            }
3739    
3740            /**
3741             * Adds an association between the team and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3742             *
3743             * @param pk the primary key of the team
3744             * @param userGroupPK the primary key of the user group
3745             */
3746            @Override
3747            public void addUserGroup(long pk, long userGroupPK) {
3748                    teamToUserGroupTableMapper.addTableMapping(0, pk, userGroupPK);
3749            }
3750    
3751            /**
3752             * Adds an association between the team and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3753             *
3754             * @param pk the primary key of the team
3755             * @param userGroup the user group
3756             */
3757            @Override
3758            public void addUserGroup(long pk,
3759                    com.liferay.portal.model.UserGroup userGroup) {
3760                    teamToUserGroupTableMapper.addTableMapping(0, pk,
3761                            userGroup.getPrimaryKey());
3762            }
3763    
3764            /**
3765             * Adds an association between the team and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3766             *
3767             * @param pk the primary key of the team
3768             * @param userGroupPKs the primary keys of the user groups
3769             */
3770            @Override
3771            public void addUserGroups(long pk, long[] userGroupPKs) {
3772                    for (long userGroupPK : userGroupPKs) {
3773                            teamToUserGroupTableMapper.addTableMapping(0, pk, userGroupPK);
3774                    }
3775            }
3776    
3777            /**
3778             * Adds an association between the team and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3779             *
3780             * @param pk the primary key of the team
3781             * @param userGroups the user groups
3782             */
3783            @Override
3784            public void addUserGroups(long pk,
3785                    List<com.liferay.portal.model.UserGroup> userGroups) {
3786                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
3787                            teamToUserGroupTableMapper.addTableMapping(0, pk,
3788                                    userGroup.getPrimaryKey());
3789                    }
3790            }
3791    
3792            /**
3793             * Clears all associations between the team and its user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3794             *
3795             * @param pk the primary key of the team to clear the associated user groups from
3796             */
3797            @Override
3798            public void clearUserGroups(long pk) {
3799                    teamToUserGroupTableMapper.deleteLeftPrimaryKeyTableMappings(0, pk);
3800            }
3801    
3802            /**
3803             * Removes the association between the team and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3804             *
3805             * @param pk the primary key of the team
3806             * @param userGroupPK the primary key of the user group
3807             */
3808            @Override
3809            public void removeUserGroup(long pk, long userGroupPK) {
3810                    teamToUserGroupTableMapper.deleteTableMapping(0, pk, userGroupPK);
3811            }
3812    
3813            /**
3814             * Removes the association between the team and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3815             *
3816             * @param pk the primary key of the team
3817             * @param userGroup the user group
3818             */
3819            @Override
3820            public void removeUserGroup(long pk,
3821                    com.liferay.portal.model.UserGroup userGroup) {
3822                    teamToUserGroupTableMapper.deleteTableMapping(0, pk,
3823                            userGroup.getPrimaryKey());
3824            }
3825    
3826            /**
3827             * Removes the association between the team and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3828             *
3829             * @param pk the primary key of the team
3830             * @param userGroupPKs the primary keys of the user groups
3831             */
3832            @Override
3833            public void removeUserGroups(long pk, long[] userGroupPKs) {
3834                    for (long userGroupPK : userGroupPKs) {
3835                            teamToUserGroupTableMapper.deleteTableMapping(0, pk, userGroupPK);
3836                    }
3837            }
3838    
3839            /**
3840             * Removes the association between the team and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3841             *
3842             * @param pk the primary key of the team
3843             * @param userGroups the user groups
3844             */
3845            @Override
3846            public void removeUserGroups(long pk,
3847                    List<com.liferay.portal.model.UserGroup> userGroups) {
3848                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
3849                            teamToUserGroupTableMapper.deleteTableMapping(0, pk,
3850                                    userGroup.getPrimaryKey());
3851                    }
3852            }
3853    
3854            /**
3855             * Sets the user groups associated with the team, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3856             *
3857             * @param pk the primary key of the team
3858             * @param userGroupPKs the primary keys of the user groups to be associated with the team
3859             */
3860            @Override
3861            public void setUserGroups(long pk, long[] userGroupPKs) {
3862                    Set<Long> newUserGroupPKsSet = SetUtil.fromArray(userGroupPKs);
3863                    Set<Long> oldUserGroupPKsSet = SetUtil.fromArray(teamToUserGroupTableMapper.getRightPrimaryKeys(
3864                                            0, pk));
3865    
3866                    Set<Long> removeUserGroupPKsSet = new HashSet<Long>(oldUserGroupPKsSet);
3867    
3868                    removeUserGroupPKsSet.removeAll(newUserGroupPKsSet);
3869    
3870                    for (long removeUserGroupPK : removeUserGroupPKsSet) {
3871                            teamToUserGroupTableMapper.deleteTableMapping(0, pk,
3872                                    removeUserGroupPK);
3873                    }
3874    
3875                    newUserGroupPKsSet.removeAll(oldUserGroupPKsSet);
3876    
3877                    for (long newUserGroupPK : newUserGroupPKsSet) {
3878                            teamToUserGroupTableMapper.addTableMapping(0, pk, newUserGroupPK);
3879                    }
3880            }
3881    
3882            /**
3883             * Sets the user groups associated with the team, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3884             *
3885             * @param pk the primary key of the team
3886             * @param userGroups the user groups to be associated with the team
3887             */
3888            @Override
3889            public void setUserGroups(long pk,
3890                    List<com.liferay.portal.model.UserGroup> userGroups) {
3891                    try {
3892                            long[] userGroupPKs = new long[userGroups.size()];
3893    
3894                            for (int i = 0; i < userGroups.size(); i++) {
3895                                    com.liferay.portal.model.UserGroup userGroup = userGroups.get(i);
3896    
3897                                    userGroupPKs[i] = userGroup.getPrimaryKey();
3898                            }
3899    
3900                            setUserGroups(pk, userGroupPKs);
3901                    }
3902                    catch (Exception e) {
3903                            throw processException(e);
3904                    }
3905            }
3906    
3907            @Override
3908            public Set<String> getBadColumnNames() {
3909                    return _badColumnNames;
3910            }
3911    
3912            @Override
3913            protected Map<String, Integer> getTableColumnsMap() {
3914                    return TeamModelImpl.TABLE_COLUMNS_MAP;
3915            }
3916    
3917            /**
3918             * Initializes the team persistence.
3919             */
3920            public void afterPropertiesSet() {
3921                    teamToUserTableMapper = TableMapperFactory.getTableMapper("Users_Teams",
3922                                    "companyId", "teamId", "userId", this, userPersistence);
3923    
3924                    teamToUserGroupTableMapper = TableMapperFactory.getTableMapper("UserGroups_Teams",
3925                                    "companyId", "teamId", "userGroupId", this, userGroupPersistence);
3926            }
3927    
3928            public void destroy() {
3929                    entityCache.removeCache(TeamImpl.class.getName());
3930                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3931                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3932                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3933    
3934                    TableMapperFactory.removeTableMapper("Users_Teams");
3935                    TableMapperFactory.removeTableMapper("UserGroups_Teams");
3936            }
3937    
3938            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3939            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3940            @BeanReference(type = UserPersistence.class)
3941            protected UserPersistence userPersistence;
3942            protected TableMapper<Team, com.liferay.portal.model.User> teamToUserTableMapper;
3943            @BeanReference(type = UserGroupPersistence.class)
3944            protected UserGroupPersistence userGroupPersistence;
3945            protected TableMapper<Team, com.liferay.portal.model.UserGroup> teamToUserGroupTableMapper;
3946            private static final String _SQL_SELECT_TEAM = "SELECT team FROM Team team";
3947            private static final String _SQL_SELECT_TEAM_WHERE_PKS_IN = "SELECT team FROM Team team WHERE teamId IN (";
3948            private static final String _SQL_SELECT_TEAM_WHERE = "SELECT team FROM Team team WHERE ";
3949            private static final String _SQL_COUNT_TEAM = "SELECT COUNT(team) FROM Team team";
3950            private static final String _SQL_COUNT_TEAM_WHERE = "SELECT COUNT(team) FROM Team team WHERE ";
3951            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "team.teamId";
3952            private static final String _FILTER_SQL_SELECT_TEAM_WHERE = "SELECT DISTINCT {team.*} FROM Team team WHERE ";
3953            private static final String _FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_1 =
3954                    "SELECT {Team.*} FROM (SELECT DISTINCT team.teamId FROM Team team WHERE ";
3955            private static final String _FILTER_SQL_SELECT_TEAM_NO_INLINE_DISTINCT_WHERE_2 =
3956                    ") TEMP_TABLE INNER JOIN Team ON TEMP_TABLE.teamId = Team.teamId";
3957            private static final String _FILTER_SQL_COUNT_TEAM_WHERE = "SELECT COUNT(DISTINCT team.teamId) AS COUNT_VALUE FROM Team team WHERE ";
3958            private static final String _FILTER_ENTITY_ALIAS = "team";
3959            private static final String _FILTER_ENTITY_TABLE = "Team";
3960            private static final String _ORDER_BY_ENTITY_ALIAS = "team.";
3961            private static final String _ORDER_BY_ENTITY_TABLE = "Team.";
3962            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Team exists with the primary key ";
3963            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Team exists with the key {";
3964            private static final Log _log = LogFactoryUtil.getLog(TeamPersistenceImpl.class);
3965            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3966                                    "uuid"
3967                            });
3968            private static final Team _nullTeam = new TeamImpl() {
3969                            @Override
3970                            public Object clone() {
3971                                    return this;
3972                            }
3973    
3974                            @Override
3975                            public CacheModel<Team> toCacheModel() {
3976                                    return _nullTeamCacheModel;
3977                            }
3978                    };
3979    
3980            private static final CacheModel<Team> _nullTeamCacheModel = new NullCacheModel();
3981    
3982            private static class NullCacheModel implements CacheModel<Team>, MVCCModel {
3983                    @Override
3984                    public long getMvccVersion() {
3985                            return -1;
3986                    }
3987    
3988                    @Override
3989                    public void setMvccVersion(long mvccVersion) {
3990                    }
3991    
3992                    @Override
3993                    public Team toEntityModel() {
3994                            return _nullTeam;
3995                    }
3996            }
3997    }