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