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