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