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