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