001    /**
002     * Copyright (c) 2000-2013 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;
016    
017    import com.liferay.portal.NoSuchMembershipRequestException;
018    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderPath;
022    import com.liferay.portal.kernel.dao.orm.Query;
023    import com.liferay.portal.kernel.dao.orm.QueryPos;
024    import com.liferay.portal.kernel.dao.orm.QueryUtil;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.GetterUtil;
030    import com.liferay.portal.kernel.util.InstanceFactory;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.MembershipRequest;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.impl.MembershipRequestImpl;
040    import com.liferay.portal.model.impl.MembershipRequestModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence implementation for the membership request service.
051     *
052     * <p>
053     * Caching information and settings can be found in <code>portal.properties</code>
054     * </p>
055     *
056     * @author Brian Wing Shun Chan
057     * @see MembershipRequestPersistence
058     * @see MembershipRequestUtil
059     * @generated
060     */
061    public class MembershipRequestPersistenceImpl extends BasePersistenceImpl<MembershipRequest>
062            implements MembershipRequestPersistence {
063            /*
064             * NOTE FOR DEVELOPERS:
065             *
066             * Never modify or reference this class directly. Always use {@link MembershipRequestUtil} to access the membership request persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
067             */
068            public static final String FINDER_CLASS_NAME_ENTITY = MembershipRequestImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
070                    ".List1";
071            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List2";
073            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
074                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
075                            MembershipRequestImpl.class,
076                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
078                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
079                            MembershipRequestImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
082                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
085                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
086                            MembershipRequestImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
088                            new String[] {
089                                    Long.class.getName(),
090                                    
091                            Integer.class.getName(), Integer.class.getName(),
092                                    OrderByComparator.class.getName()
093                            });
094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
095                    new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
096                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
097                            MembershipRequestImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
099                            new String[] { Long.class.getName() },
100                            MembershipRequestModelImpl.GROUPID_COLUMN_BITMASK |
101                            MembershipRequestModelImpl.CREATEDATE_COLUMN_BITMASK);
102            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
103                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
105                            new String[] { Long.class.getName() });
106    
107            /**
108             * Returns all the membership requests where groupId = &#63;.
109             *
110             * @param groupId the group ID
111             * @return the matching membership requests
112             * @throws SystemException if a system exception occurred
113             */
114            @Override
115            public List<MembershipRequest> findByGroupId(long groupId)
116                    throws SystemException {
117                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118            }
119    
120            /**
121             * Returns a range of all the membership requests where groupId = &#63;.
122             *
123             * <p>
124             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
125             * </p>
126             *
127             * @param groupId the group ID
128             * @param start the lower bound of the range of membership requests
129             * @param end the upper bound of the range of membership requests (not inclusive)
130             * @return the range of matching membership requests
131             * @throws SystemException if a system exception occurred
132             */
133            @Override
134            public List<MembershipRequest> findByGroupId(long groupId, int start,
135                    int end) throws SystemException {
136                    return findByGroupId(groupId, start, end, null);
137            }
138    
139            /**
140             * Returns an ordered range of all the membership requests where groupId = &#63;.
141             *
142             * <p>
143             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
144             * </p>
145             *
146             * @param groupId the group ID
147             * @param start the lower bound of the range of membership requests
148             * @param end the upper bound of the range of membership requests (not inclusive)
149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
150             * @return the ordered range of matching membership requests
151             * @throws SystemException if a system exception occurred
152             */
153            @Override
154            public List<MembershipRequest> findByGroupId(long groupId, int start,
155                    int end, OrderByComparator orderByComparator) throws SystemException {
156                    boolean pagination = true;
157                    FinderPath finderPath = null;
158                    Object[] finderArgs = null;
159    
160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161                                    (orderByComparator == null)) {
162                            pagination = false;
163                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
164                            finderArgs = new Object[] { groupId };
165                    }
166                    else {
167                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
168                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
169                    }
170    
171                    List<MembershipRequest> list = (List<MembershipRequest>)FinderCacheUtil.getResult(finderPath,
172                                    finderArgs, this);
173    
174                    if ((list != null) && !list.isEmpty()) {
175                            for (MembershipRequest membershipRequest : list) {
176                                    if ((groupId != membershipRequest.getGroupId())) {
177                                            list = null;
178    
179                                            break;
180                                    }
181                            }
182                    }
183    
184                    if (list == null) {
185                            StringBundler query = null;
186    
187                            if (orderByComparator != null) {
188                                    query = new StringBundler(3 +
189                                                    (orderByComparator.getOrderByFields().length * 3));
190                            }
191                            else {
192                                    query = new StringBundler(3);
193                            }
194    
195                            query.append(_SQL_SELECT_MEMBERSHIPREQUEST_WHERE);
196    
197                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
198    
199                            if (orderByComparator != null) {
200                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
201                                            orderByComparator);
202                            }
203                            else
204                             if (pagination) {
205                                    query.append(MembershipRequestModelImpl.ORDER_BY_JPQL);
206                            }
207    
208                            String sql = query.toString();
209    
210                            Session session = null;
211    
212                            try {
213                                    session = openSession();
214    
215                                    Query q = session.createQuery(sql);
216    
217                                    QueryPos qPos = QueryPos.getInstance(q);
218    
219                                    qPos.add(groupId);
220    
221                                    if (!pagination) {
222                                            list = (List<MembershipRequest>)QueryUtil.list(q,
223                                                            getDialect(), start, end, false);
224    
225                                            Collections.sort(list);
226    
227                                            list = new UnmodifiableList<MembershipRequest>(list);
228                                    }
229                                    else {
230                                            list = (List<MembershipRequest>)QueryUtil.list(q,
231                                                            getDialect(), start, end);
232                                    }
233    
234                                    cacheResult(list);
235    
236                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
237                            }
238                            catch (Exception e) {
239                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
240    
241                                    throw processException(e);
242                            }
243                            finally {
244                                    closeSession(session);
245                            }
246                    }
247    
248                    return list;
249            }
250    
251            /**
252             * Returns the first membership request in the ordered set where groupId = &#63;.
253             *
254             * @param groupId the group ID
255             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
256             * @return the first matching membership request
257             * @throws com.liferay.portal.NoSuchMembershipRequestException if a matching membership request could not be found
258             * @throws SystemException if a system exception occurred
259             */
260            @Override
261            public MembershipRequest findByGroupId_First(long groupId,
262                    OrderByComparator orderByComparator)
263                    throws NoSuchMembershipRequestException, SystemException {
264                    MembershipRequest membershipRequest = fetchByGroupId_First(groupId,
265                                    orderByComparator);
266    
267                    if (membershipRequest != null) {
268                            return membershipRequest;
269                    }
270    
271                    StringBundler msg = new StringBundler(4);
272    
273                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
274    
275                    msg.append("groupId=");
276                    msg.append(groupId);
277    
278                    msg.append(StringPool.CLOSE_CURLY_BRACE);
279    
280                    throw new NoSuchMembershipRequestException(msg.toString());
281            }
282    
283            /**
284             * Returns the first membership request in the ordered set where groupId = &#63;.
285             *
286             * @param groupId the group ID
287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
288             * @return the first matching membership request, or <code>null</code> if a matching membership request could not be found
289             * @throws SystemException if a system exception occurred
290             */
291            @Override
292            public MembershipRequest fetchByGroupId_First(long groupId,
293                    OrderByComparator orderByComparator) throws SystemException {
294                    List<MembershipRequest> list = findByGroupId(groupId, 0, 1,
295                                    orderByComparator);
296    
297                    if (!list.isEmpty()) {
298                            return list.get(0);
299                    }
300    
301                    return null;
302            }
303    
304            /**
305             * Returns the last membership request in the ordered set where groupId = &#63;.
306             *
307             * @param groupId the group ID
308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
309             * @return the last matching membership request
310             * @throws com.liferay.portal.NoSuchMembershipRequestException if a matching membership request could not be found
311             * @throws SystemException if a system exception occurred
312             */
313            @Override
314            public MembershipRequest findByGroupId_Last(long groupId,
315                    OrderByComparator orderByComparator)
316                    throws NoSuchMembershipRequestException, SystemException {
317                    MembershipRequest membershipRequest = fetchByGroupId_Last(groupId,
318                                    orderByComparator);
319    
320                    if (membershipRequest != null) {
321                            return membershipRequest;
322                    }
323    
324                    StringBundler msg = new StringBundler(4);
325    
326                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327    
328                    msg.append("groupId=");
329                    msg.append(groupId);
330    
331                    msg.append(StringPool.CLOSE_CURLY_BRACE);
332    
333                    throw new NoSuchMembershipRequestException(msg.toString());
334            }
335    
336            /**
337             * Returns the last membership request in the ordered set where groupId = &#63;.
338             *
339             * @param groupId the group ID
340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
341             * @return the last matching membership request, or <code>null</code> if a matching membership request could not be found
342             * @throws SystemException if a system exception occurred
343             */
344            @Override
345            public MembershipRequest fetchByGroupId_Last(long groupId,
346                    OrderByComparator orderByComparator) throws SystemException {
347                    int count = countByGroupId(groupId);
348    
349                    if (count == 0) {
350                            return null;
351                    }
352    
353                    List<MembershipRequest> list = findByGroupId(groupId, count - 1, count,
354                                    orderByComparator);
355    
356                    if (!list.isEmpty()) {
357                            return list.get(0);
358                    }
359    
360                    return null;
361            }
362    
363            /**
364             * Returns the membership requests before and after the current membership request in the ordered set where groupId = &#63;.
365             *
366             * @param membershipRequestId the primary key of the current membership request
367             * @param groupId the group ID
368             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
369             * @return the previous, current, and next membership request
370             * @throws com.liferay.portal.NoSuchMembershipRequestException if a membership request with the primary key could not be found
371             * @throws SystemException if a system exception occurred
372             */
373            @Override
374            public MembershipRequest[] findByGroupId_PrevAndNext(
375                    long membershipRequestId, long groupId,
376                    OrderByComparator orderByComparator)
377                    throws NoSuchMembershipRequestException, SystemException {
378                    MembershipRequest membershipRequest = findByPrimaryKey(membershipRequestId);
379    
380                    Session session = null;
381    
382                    try {
383                            session = openSession();
384    
385                            MembershipRequest[] array = new MembershipRequestImpl[3];
386    
387                            array[0] = getByGroupId_PrevAndNext(session, membershipRequest,
388                                            groupId, orderByComparator, true);
389    
390                            array[1] = membershipRequest;
391    
392                            array[2] = getByGroupId_PrevAndNext(session, membershipRequest,
393                                            groupId, orderByComparator, false);
394    
395                            return array;
396                    }
397                    catch (Exception e) {
398                            throw processException(e);
399                    }
400                    finally {
401                            closeSession(session);
402                    }
403            }
404    
405            protected MembershipRequest getByGroupId_PrevAndNext(Session session,
406                    MembershipRequest membershipRequest, long groupId,
407                    OrderByComparator orderByComparator, boolean previous) {
408                    StringBundler query = null;
409    
410                    if (orderByComparator != null) {
411                            query = new StringBundler(6 +
412                                            (orderByComparator.getOrderByFields().length * 6));
413                    }
414                    else {
415                            query = new StringBundler(3);
416                    }
417    
418                    query.append(_SQL_SELECT_MEMBERSHIPREQUEST_WHERE);
419    
420                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
421    
422                    if (orderByComparator != null) {
423                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
424    
425                            if (orderByConditionFields.length > 0) {
426                                    query.append(WHERE_AND);
427                            }
428    
429                            for (int i = 0; i < orderByConditionFields.length; i++) {
430                                    query.append(_ORDER_BY_ENTITY_ALIAS);
431                                    query.append(orderByConditionFields[i]);
432    
433                                    if ((i + 1) < orderByConditionFields.length) {
434                                            if (orderByComparator.isAscending() ^ previous) {
435                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
436                                            }
437                                            else {
438                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
439                                            }
440                                    }
441                                    else {
442                                            if (orderByComparator.isAscending() ^ previous) {
443                                                    query.append(WHERE_GREATER_THAN);
444                                            }
445                                            else {
446                                                    query.append(WHERE_LESSER_THAN);
447                                            }
448                                    }
449                            }
450    
451                            query.append(ORDER_BY_CLAUSE);
452    
453                            String[] orderByFields = orderByComparator.getOrderByFields();
454    
455                            for (int i = 0; i < orderByFields.length; i++) {
456                                    query.append(_ORDER_BY_ENTITY_ALIAS);
457                                    query.append(orderByFields[i]);
458    
459                                    if ((i + 1) < orderByFields.length) {
460                                            if (orderByComparator.isAscending() ^ previous) {
461                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
462                                            }
463                                            else {
464                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
465                                            }
466                                    }
467                                    else {
468                                            if (orderByComparator.isAscending() ^ previous) {
469                                                    query.append(ORDER_BY_ASC);
470                                            }
471                                            else {
472                                                    query.append(ORDER_BY_DESC);
473                                            }
474                                    }
475                            }
476                    }
477                    else {
478                            query.append(MembershipRequestModelImpl.ORDER_BY_JPQL);
479                    }
480    
481                    String sql = query.toString();
482    
483                    Query q = session.createQuery(sql);
484    
485                    q.setFirstResult(0);
486                    q.setMaxResults(2);
487    
488                    QueryPos qPos = QueryPos.getInstance(q);
489    
490                    qPos.add(groupId);
491    
492                    if (orderByComparator != null) {
493                            Object[] values = orderByComparator.getOrderByConditionValues(membershipRequest);
494    
495                            for (Object value : values) {
496                                    qPos.add(value);
497                            }
498                    }
499    
500                    List<MembershipRequest> list = q.list();
501    
502                    if (list.size() == 2) {
503                            return list.get(1);
504                    }
505                    else {
506                            return null;
507                    }
508            }
509    
510            /**
511             * Removes all the membership requests where groupId = &#63; from the database.
512             *
513             * @param groupId the group ID
514             * @throws SystemException if a system exception occurred
515             */
516            @Override
517            public void removeByGroupId(long groupId) throws SystemException {
518                    for (MembershipRequest membershipRequest : findByGroupId(groupId,
519                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
520                            remove(membershipRequest);
521                    }
522            }
523    
524            /**
525             * Returns the number of membership requests where groupId = &#63;.
526             *
527             * @param groupId the group ID
528             * @return the number of matching membership requests
529             * @throws SystemException if a system exception occurred
530             */
531            @Override
532            public int countByGroupId(long groupId) throws SystemException {
533                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
534    
535                    Object[] finderArgs = new Object[] { groupId };
536    
537                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
538                                    this);
539    
540                    if (count == null) {
541                            StringBundler query = new StringBundler(2);
542    
543                            query.append(_SQL_COUNT_MEMBERSHIPREQUEST_WHERE);
544    
545                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
546    
547                            String sql = query.toString();
548    
549                            Session session = null;
550    
551                            try {
552                                    session = openSession();
553    
554                                    Query q = session.createQuery(sql);
555    
556                                    QueryPos qPos = QueryPos.getInstance(q);
557    
558                                    qPos.add(groupId);
559    
560                                    count = (Long)q.uniqueResult();
561    
562                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
563                            }
564                            catch (Exception e) {
565                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
566    
567                                    throw processException(e);
568                            }
569                            finally {
570                                    closeSession(session);
571                            }
572                    }
573    
574                    return count.intValue();
575            }
576    
577            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "membershipRequest.groupId = ?";
578            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
579                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
580                            MembershipRequestImpl.class,
581                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
582                            new String[] {
583                                    Long.class.getName(),
584                                    
585                            Integer.class.getName(), Integer.class.getName(),
586                                    OrderByComparator.class.getName()
587                            });
588            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
589                    new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
590                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
591                            MembershipRequestImpl.class,
592                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
593                            new String[] { Long.class.getName() },
594                            MembershipRequestModelImpl.USERID_COLUMN_BITMASK |
595                            MembershipRequestModelImpl.CREATEDATE_COLUMN_BITMASK);
596            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
597                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
598                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
599                            new String[] { Long.class.getName() });
600    
601            /**
602             * Returns all the membership requests where userId = &#63;.
603             *
604             * @param userId the user ID
605             * @return the matching membership requests
606             * @throws SystemException if a system exception occurred
607             */
608            @Override
609            public List<MembershipRequest> findByUserId(long userId)
610                    throws SystemException {
611                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
612            }
613    
614            /**
615             * Returns a range of all the membership requests where userId = &#63;.
616             *
617             * <p>
618             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
619             * </p>
620             *
621             * @param userId the user ID
622             * @param start the lower bound of the range of membership requests
623             * @param end the upper bound of the range of membership requests (not inclusive)
624             * @return the range of matching membership requests
625             * @throws SystemException if a system exception occurred
626             */
627            @Override
628            public List<MembershipRequest> findByUserId(long userId, int start, int end)
629                    throws SystemException {
630                    return findByUserId(userId, start, end, null);
631            }
632    
633            /**
634             * Returns an ordered range of all the membership requests where userId = &#63;.
635             *
636             * <p>
637             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
638             * </p>
639             *
640             * @param userId the user ID
641             * @param start the lower bound of the range of membership requests
642             * @param end the upper bound of the range of membership requests (not inclusive)
643             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
644             * @return the ordered range of matching membership requests
645             * @throws SystemException if a system exception occurred
646             */
647            @Override
648            public List<MembershipRequest> findByUserId(long userId, int start,
649                    int end, OrderByComparator orderByComparator) throws SystemException {
650                    boolean pagination = true;
651                    FinderPath finderPath = null;
652                    Object[] finderArgs = null;
653    
654                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
655                                    (orderByComparator == null)) {
656                            pagination = false;
657                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
658                            finderArgs = new Object[] { userId };
659                    }
660                    else {
661                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
662                            finderArgs = new Object[] { userId, start, end, orderByComparator };
663                    }
664    
665                    List<MembershipRequest> list = (List<MembershipRequest>)FinderCacheUtil.getResult(finderPath,
666                                    finderArgs, this);
667    
668                    if ((list != null) && !list.isEmpty()) {
669                            for (MembershipRequest membershipRequest : list) {
670                                    if ((userId != membershipRequest.getUserId())) {
671                                            list = null;
672    
673                                            break;
674                                    }
675                            }
676                    }
677    
678                    if (list == null) {
679                            StringBundler query = null;
680    
681                            if (orderByComparator != null) {
682                                    query = new StringBundler(3 +
683                                                    (orderByComparator.getOrderByFields().length * 3));
684                            }
685                            else {
686                                    query = new StringBundler(3);
687                            }
688    
689                            query.append(_SQL_SELECT_MEMBERSHIPREQUEST_WHERE);
690    
691                            query.append(_FINDER_COLUMN_USERID_USERID_2);
692    
693                            if (orderByComparator != null) {
694                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
695                                            orderByComparator);
696                            }
697                            else
698                             if (pagination) {
699                                    query.append(MembershipRequestModelImpl.ORDER_BY_JPQL);
700                            }
701    
702                            String sql = query.toString();
703    
704                            Session session = null;
705    
706                            try {
707                                    session = openSession();
708    
709                                    Query q = session.createQuery(sql);
710    
711                                    QueryPos qPos = QueryPos.getInstance(q);
712    
713                                    qPos.add(userId);
714    
715                                    if (!pagination) {
716                                            list = (List<MembershipRequest>)QueryUtil.list(q,
717                                                            getDialect(), start, end, false);
718    
719                                            Collections.sort(list);
720    
721                                            list = new UnmodifiableList<MembershipRequest>(list);
722                                    }
723                                    else {
724                                            list = (List<MembershipRequest>)QueryUtil.list(q,
725                                                            getDialect(), start, end);
726                                    }
727    
728                                    cacheResult(list);
729    
730                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
731                            }
732                            catch (Exception e) {
733                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
734    
735                                    throw processException(e);
736                            }
737                            finally {
738                                    closeSession(session);
739                            }
740                    }
741    
742                    return list;
743            }
744    
745            /**
746             * Returns the first membership request in the ordered set where userId = &#63;.
747             *
748             * @param userId the user ID
749             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
750             * @return the first matching membership request
751             * @throws com.liferay.portal.NoSuchMembershipRequestException if a matching membership request could not be found
752             * @throws SystemException if a system exception occurred
753             */
754            @Override
755            public MembershipRequest findByUserId_First(long userId,
756                    OrderByComparator orderByComparator)
757                    throws NoSuchMembershipRequestException, SystemException {
758                    MembershipRequest membershipRequest = fetchByUserId_First(userId,
759                                    orderByComparator);
760    
761                    if (membershipRequest != null) {
762                            return membershipRequest;
763                    }
764    
765                    StringBundler msg = new StringBundler(4);
766    
767                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
768    
769                    msg.append("userId=");
770                    msg.append(userId);
771    
772                    msg.append(StringPool.CLOSE_CURLY_BRACE);
773    
774                    throw new NoSuchMembershipRequestException(msg.toString());
775            }
776    
777            /**
778             * Returns the first membership request in the ordered set where userId = &#63;.
779             *
780             * @param userId the user ID
781             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
782             * @return the first matching membership request, or <code>null</code> if a matching membership request could not be found
783             * @throws SystemException if a system exception occurred
784             */
785            @Override
786            public MembershipRequest fetchByUserId_First(long userId,
787                    OrderByComparator orderByComparator) throws SystemException {
788                    List<MembershipRequest> list = findByUserId(userId, 0, 1,
789                                    orderByComparator);
790    
791                    if (!list.isEmpty()) {
792                            return list.get(0);
793                    }
794    
795                    return null;
796            }
797    
798            /**
799             * Returns the last membership request in the ordered set where userId = &#63;.
800             *
801             * @param userId the user ID
802             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
803             * @return the last matching membership request
804             * @throws com.liferay.portal.NoSuchMembershipRequestException if a matching membership request could not be found
805             * @throws SystemException if a system exception occurred
806             */
807            @Override
808            public MembershipRequest findByUserId_Last(long userId,
809                    OrderByComparator orderByComparator)
810                    throws NoSuchMembershipRequestException, SystemException {
811                    MembershipRequest membershipRequest = fetchByUserId_Last(userId,
812                                    orderByComparator);
813    
814                    if (membershipRequest != null) {
815                            return membershipRequest;
816                    }
817    
818                    StringBundler msg = new StringBundler(4);
819    
820                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
821    
822                    msg.append("userId=");
823                    msg.append(userId);
824    
825                    msg.append(StringPool.CLOSE_CURLY_BRACE);
826    
827                    throw new NoSuchMembershipRequestException(msg.toString());
828            }
829    
830            /**
831             * Returns the last membership request in the ordered set where userId = &#63;.
832             *
833             * @param userId the user ID
834             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
835             * @return the last matching membership request, or <code>null</code> if a matching membership request could not be found
836             * @throws SystemException if a system exception occurred
837             */
838            @Override
839            public MembershipRequest fetchByUserId_Last(long userId,
840                    OrderByComparator orderByComparator) throws SystemException {
841                    int count = countByUserId(userId);
842    
843                    if (count == 0) {
844                            return null;
845                    }
846    
847                    List<MembershipRequest> list = findByUserId(userId, count - 1, count,
848                                    orderByComparator);
849    
850                    if (!list.isEmpty()) {
851                            return list.get(0);
852                    }
853    
854                    return null;
855            }
856    
857            /**
858             * Returns the membership requests before and after the current membership request in the ordered set where userId = &#63;.
859             *
860             * @param membershipRequestId the primary key of the current membership request
861             * @param userId the user ID
862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
863             * @return the previous, current, and next membership request
864             * @throws com.liferay.portal.NoSuchMembershipRequestException if a membership request with the primary key could not be found
865             * @throws SystemException if a system exception occurred
866             */
867            @Override
868            public MembershipRequest[] findByUserId_PrevAndNext(
869                    long membershipRequestId, long userId,
870                    OrderByComparator orderByComparator)
871                    throws NoSuchMembershipRequestException, SystemException {
872                    MembershipRequest membershipRequest = findByPrimaryKey(membershipRequestId);
873    
874                    Session session = null;
875    
876                    try {
877                            session = openSession();
878    
879                            MembershipRequest[] array = new MembershipRequestImpl[3];
880    
881                            array[0] = getByUserId_PrevAndNext(session, membershipRequest,
882                                            userId, orderByComparator, true);
883    
884                            array[1] = membershipRequest;
885    
886                            array[2] = getByUserId_PrevAndNext(session, membershipRequest,
887                                            userId, orderByComparator, false);
888    
889                            return array;
890                    }
891                    catch (Exception e) {
892                            throw processException(e);
893                    }
894                    finally {
895                            closeSession(session);
896                    }
897            }
898    
899            protected MembershipRequest getByUserId_PrevAndNext(Session session,
900                    MembershipRequest membershipRequest, long userId,
901                    OrderByComparator orderByComparator, boolean previous) {
902                    StringBundler query = null;
903    
904                    if (orderByComparator != null) {
905                            query = new StringBundler(6 +
906                                            (orderByComparator.getOrderByFields().length * 6));
907                    }
908                    else {
909                            query = new StringBundler(3);
910                    }
911    
912                    query.append(_SQL_SELECT_MEMBERSHIPREQUEST_WHERE);
913    
914                    query.append(_FINDER_COLUMN_USERID_USERID_2);
915    
916                    if (orderByComparator != null) {
917                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
918    
919                            if (orderByConditionFields.length > 0) {
920                                    query.append(WHERE_AND);
921                            }
922    
923                            for (int i = 0; i < orderByConditionFields.length; i++) {
924                                    query.append(_ORDER_BY_ENTITY_ALIAS);
925                                    query.append(orderByConditionFields[i]);
926    
927                                    if ((i + 1) < orderByConditionFields.length) {
928                                            if (orderByComparator.isAscending() ^ previous) {
929                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
930                                            }
931                                            else {
932                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
933                                            }
934                                    }
935                                    else {
936                                            if (orderByComparator.isAscending() ^ previous) {
937                                                    query.append(WHERE_GREATER_THAN);
938                                            }
939                                            else {
940                                                    query.append(WHERE_LESSER_THAN);
941                                            }
942                                    }
943                            }
944    
945                            query.append(ORDER_BY_CLAUSE);
946    
947                            String[] orderByFields = orderByComparator.getOrderByFields();
948    
949                            for (int i = 0; i < orderByFields.length; i++) {
950                                    query.append(_ORDER_BY_ENTITY_ALIAS);
951                                    query.append(orderByFields[i]);
952    
953                                    if ((i + 1) < orderByFields.length) {
954                                            if (orderByComparator.isAscending() ^ previous) {
955                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
956                                            }
957                                            else {
958                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
959                                            }
960                                    }
961                                    else {
962                                            if (orderByComparator.isAscending() ^ previous) {
963                                                    query.append(ORDER_BY_ASC);
964                                            }
965                                            else {
966                                                    query.append(ORDER_BY_DESC);
967                                            }
968                                    }
969                            }
970                    }
971                    else {
972                            query.append(MembershipRequestModelImpl.ORDER_BY_JPQL);
973                    }
974    
975                    String sql = query.toString();
976    
977                    Query q = session.createQuery(sql);
978    
979                    q.setFirstResult(0);
980                    q.setMaxResults(2);
981    
982                    QueryPos qPos = QueryPos.getInstance(q);
983    
984                    qPos.add(userId);
985    
986                    if (orderByComparator != null) {
987                            Object[] values = orderByComparator.getOrderByConditionValues(membershipRequest);
988    
989                            for (Object value : values) {
990                                    qPos.add(value);
991                            }
992                    }
993    
994                    List<MembershipRequest> list = q.list();
995    
996                    if (list.size() == 2) {
997                            return list.get(1);
998                    }
999                    else {
1000                            return null;
1001                    }
1002            }
1003    
1004            /**
1005             * Removes all the membership requests where userId = &#63; from the database.
1006             *
1007             * @param userId the user ID
1008             * @throws SystemException if a system exception occurred
1009             */
1010            @Override
1011            public void removeByUserId(long userId) throws SystemException {
1012                    for (MembershipRequest membershipRequest : findByUserId(userId,
1013                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1014                            remove(membershipRequest);
1015                    }
1016            }
1017    
1018            /**
1019             * Returns the number of membership requests where userId = &#63;.
1020             *
1021             * @param userId the user ID
1022             * @return the number of matching membership requests
1023             * @throws SystemException if a system exception occurred
1024             */
1025            @Override
1026            public int countByUserId(long userId) throws SystemException {
1027                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1028    
1029                    Object[] finderArgs = new Object[] { userId };
1030    
1031                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1032                                    this);
1033    
1034                    if (count == null) {
1035                            StringBundler query = new StringBundler(2);
1036    
1037                            query.append(_SQL_COUNT_MEMBERSHIPREQUEST_WHERE);
1038    
1039                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1040    
1041                            String sql = query.toString();
1042    
1043                            Session session = null;
1044    
1045                            try {
1046                                    session = openSession();
1047    
1048                                    Query q = session.createQuery(sql);
1049    
1050                                    QueryPos qPos = QueryPos.getInstance(q);
1051    
1052                                    qPos.add(userId);
1053    
1054                                    count = (Long)q.uniqueResult();
1055    
1056                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1057                            }
1058                            catch (Exception e) {
1059                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1060    
1061                                    throw processException(e);
1062                            }
1063                            finally {
1064                                    closeSession(session);
1065                            }
1066                    }
1067    
1068                    return count.intValue();
1069            }
1070    
1071            private static final String _FINDER_COLUMN_USERID_USERID_2 = "membershipRequest.userId = ?";
1072            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
1073                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
1074                            MembershipRequestImpl.class,
1075                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
1076                            new String[] {
1077                                    Long.class.getName(), Integer.class.getName(),
1078                                    
1079                            Integer.class.getName(), Integer.class.getName(),
1080                                    OrderByComparator.class.getName()
1081                            });
1082            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
1083                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
1084                            MembershipRequestImpl.class,
1085                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
1086                            new String[] { Long.class.getName(), Integer.class.getName() },
1087                            MembershipRequestModelImpl.GROUPID_COLUMN_BITMASK |
1088                            MembershipRequestModelImpl.STATUSID_COLUMN_BITMASK |
1089                            MembershipRequestModelImpl.CREATEDATE_COLUMN_BITMASK);
1090            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
1091                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
1092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
1093                            new String[] { Long.class.getName(), Integer.class.getName() });
1094    
1095            /**
1096             * Returns all the membership requests where groupId = &#63; and statusId = &#63;.
1097             *
1098             * @param groupId the group ID
1099             * @param statusId the status ID
1100             * @return the matching membership requests
1101             * @throws SystemException if a system exception occurred
1102             */
1103            @Override
1104            public List<MembershipRequest> findByG_S(long groupId, int statusId)
1105                    throws SystemException {
1106                    return findByG_S(groupId, statusId, QueryUtil.ALL_POS,
1107                            QueryUtil.ALL_POS, null);
1108            }
1109    
1110            /**
1111             * Returns a range of all the membership requests where groupId = &#63; and statusId = &#63;.
1112             *
1113             * <p>
1114             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
1115             * </p>
1116             *
1117             * @param groupId the group ID
1118             * @param statusId the status ID
1119             * @param start the lower bound of the range of membership requests
1120             * @param end the upper bound of the range of membership requests (not inclusive)
1121             * @return the range of matching membership requests
1122             * @throws SystemException if a system exception occurred
1123             */
1124            @Override
1125            public List<MembershipRequest> findByG_S(long groupId, int statusId,
1126                    int start, int end) throws SystemException {
1127                    return findByG_S(groupId, statusId, start, end, null);
1128            }
1129    
1130            /**
1131             * Returns an ordered range of all the membership requests where groupId = &#63; and statusId = &#63;.
1132             *
1133             * <p>
1134             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
1135             * </p>
1136             *
1137             * @param groupId the group ID
1138             * @param statusId the status ID
1139             * @param start the lower bound of the range of membership requests
1140             * @param end the upper bound of the range of membership requests (not inclusive)
1141             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1142             * @return the ordered range of matching membership requests
1143             * @throws SystemException if a system exception occurred
1144             */
1145            @Override
1146            public List<MembershipRequest> findByG_S(long groupId, int statusId,
1147                    int start, int end, OrderByComparator orderByComparator)
1148                    throws SystemException {
1149                    boolean pagination = true;
1150                    FinderPath finderPath = null;
1151                    Object[] finderArgs = null;
1152    
1153                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1154                                    (orderByComparator == null)) {
1155                            pagination = false;
1156                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
1157                            finderArgs = new Object[] { groupId, statusId };
1158                    }
1159                    else {
1160                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
1161                            finderArgs = new Object[] {
1162                                            groupId, statusId,
1163                                            
1164                                            start, end, orderByComparator
1165                                    };
1166                    }
1167    
1168                    List<MembershipRequest> list = (List<MembershipRequest>)FinderCacheUtil.getResult(finderPath,
1169                                    finderArgs, this);
1170    
1171                    if ((list != null) && !list.isEmpty()) {
1172                            for (MembershipRequest membershipRequest : list) {
1173                                    if ((groupId != membershipRequest.getGroupId()) ||
1174                                                    (statusId != membershipRequest.getStatusId())) {
1175                                            list = null;
1176    
1177                                            break;
1178                                    }
1179                            }
1180                    }
1181    
1182                    if (list == null) {
1183                            StringBundler query = null;
1184    
1185                            if (orderByComparator != null) {
1186                                    query = new StringBundler(4 +
1187                                                    (orderByComparator.getOrderByFields().length * 3));
1188                            }
1189                            else {
1190                                    query = new StringBundler(4);
1191                            }
1192    
1193                            query.append(_SQL_SELECT_MEMBERSHIPREQUEST_WHERE);
1194    
1195                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1196    
1197                            query.append(_FINDER_COLUMN_G_S_STATUSID_2);
1198    
1199                            if (orderByComparator != null) {
1200                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1201                                            orderByComparator);
1202                            }
1203                            else
1204                             if (pagination) {
1205                                    query.append(MembershipRequestModelImpl.ORDER_BY_JPQL);
1206                            }
1207    
1208                            String sql = query.toString();
1209    
1210                            Session session = null;
1211    
1212                            try {
1213                                    session = openSession();
1214    
1215                                    Query q = session.createQuery(sql);
1216    
1217                                    QueryPos qPos = QueryPos.getInstance(q);
1218    
1219                                    qPos.add(groupId);
1220    
1221                                    qPos.add(statusId);
1222    
1223                                    if (!pagination) {
1224                                            list = (List<MembershipRequest>)QueryUtil.list(q,
1225                                                            getDialect(), start, end, false);
1226    
1227                                            Collections.sort(list);
1228    
1229                                            list = new UnmodifiableList<MembershipRequest>(list);
1230                                    }
1231                                    else {
1232                                            list = (List<MembershipRequest>)QueryUtil.list(q,
1233                                                            getDialect(), start, end);
1234                                    }
1235    
1236                                    cacheResult(list);
1237    
1238                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1239                            }
1240                            catch (Exception e) {
1241                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1242    
1243                                    throw processException(e);
1244                            }
1245                            finally {
1246                                    closeSession(session);
1247                            }
1248                    }
1249    
1250                    return list;
1251            }
1252    
1253            /**
1254             * Returns the first membership request in the ordered set where groupId = &#63; and statusId = &#63;.
1255             *
1256             * @param groupId the group ID
1257             * @param statusId the status ID
1258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1259             * @return the first matching membership request
1260             * @throws com.liferay.portal.NoSuchMembershipRequestException if a matching membership request could not be found
1261             * @throws SystemException if a system exception occurred
1262             */
1263            @Override
1264            public MembershipRequest findByG_S_First(long groupId, int statusId,
1265                    OrderByComparator orderByComparator)
1266                    throws NoSuchMembershipRequestException, SystemException {
1267                    MembershipRequest membershipRequest = fetchByG_S_First(groupId,
1268                                    statusId, orderByComparator);
1269    
1270                    if (membershipRequest != null) {
1271                            return membershipRequest;
1272                    }
1273    
1274                    StringBundler msg = new StringBundler(6);
1275    
1276                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1277    
1278                    msg.append("groupId=");
1279                    msg.append(groupId);
1280    
1281                    msg.append(", statusId=");
1282                    msg.append(statusId);
1283    
1284                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1285    
1286                    throw new NoSuchMembershipRequestException(msg.toString());
1287            }
1288    
1289            /**
1290             * Returns the first membership request in the ordered set where groupId = &#63; and statusId = &#63;.
1291             *
1292             * @param groupId the group ID
1293             * @param statusId the status ID
1294             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1295             * @return the first matching membership request, or <code>null</code> if a matching membership request could not be found
1296             * @throws SystemException if a system exception occurred
1297             */
1298            @Override
1299            public MembershipRequest fetchByG_S_First(long groupId, int statusId,
1300                    OrderByComparator orderByComparator) throws SystemException {
1301                    List<MembershipRequest> list = findByG_S(groupId, statusId, 0, 1,
1302                                    orderByComparator);
1303    
1304                    if (!list.isEmpty()) {
1305                            return list.get(0);
1306                    }
1307    
1308                    return null;
1309            }
1310    
1311            /**
1312             * Returns the last membership request in the ordered set where groupId = &#63; and statusId = &#63;.
1313             *
1314             * @param groupId the group ID
1315             * @param statusId the status ID
1316             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1317             * @return the last matching membership request
1318             * @throws com.liferay.portal.NoSuchMembershipRequestException if a matching membership request could not be found
1319             * @throws SystemException if a system exception occurred
1320             */
1321            @Override
1322            public MembershipRequest findByG_S_Last(long groupId, int statusId,
1323                    OrderByComparator orderByComparator)
1324                    throws NoSuchMembershipRequestException, SystemException {
1325                    MembershipRequest membershipRequest = fetchByG_S_Last(groupId,
1326                                    statusId, orderByComparator);
1327    
1328                    if (membershipRequest != null) {
1329                            return membershipRequest;
1330                    }
1331    
1332                    StringBundler msg = new StringBundler(6);
1333    
1334                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1335    
1336                    msg.append("groupId=");
1337                    msg.append(groupId);
1338    
1339                    msg.append(", statusId=");
1340                    msg.append(statusId);
1341    
1342                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1343    
1344                    throw new NoSuchMembershipRequestException(msg.toString());
1345            }
1346    
1347            /**
1348             * Returns the last membership request in the ordered set where groupId = &#63; and statusId = &#63;.
1349             *
1350             * @param groupId the group ID
1351             * @param statusId the status ID
1352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1353             * @return the last matching membership request, or <code>null</code> if a matching membership request could not be found
1354             * @throws SystemException if a system exception occurred
1355             */
1356            @Override
1357            public MembershipRequest fetchByG_S_Last(long groupId, int statusId,
1358                    OrderByComparator orderByComparator) throws SystemException {
1359                    int count = countByG_S(groupId, statusId);
1360    
1361                    if (count == 0) {
1362                            return null;
1363                    }
1364    
1365                    List<MembershipRequest> list = findByG_S(groupId, statusId, count - 1,
1366                                    count, orderByComparator);
1367    
1368                    if (!list.isEmpty()) {
1369                            return list.get(0);
1370                    }
1371    
1372                    return null;
1373            }
1374    
1375            /**
1376             * Returns the membership requests before and after the current membership request in the ordered set where groupId = &#63; and statusId = &#63;.
1377             *
1378             * @param membershipRequestId the primary key of the current membership request
1379             * @param groupId the group ID
1380             * @param statusId the status ID
1381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1382             * @return the previous, current, and next membership request
1383             * @throws com.liferay.portal.NoSuchMembershipRequestException if a membership request with the primary key could not be found
1384             * @throws SystemException if a system exception occurred
1385             */
1386            @Override
1387            public MembershipRequest[] findByG_S_PrevAndNext(long membershipRequestId,
1388                    long groupId, int statusId, OrderByComparator orderByComparator)
1389                    throws NoSuchMembershipRequestException, SystemException {
1390                    MembershipRequest membershipRequest = findByPrimaryKey(membershipRequestId);
1391    
1392                    Session session = null;
1393    
1394                    try {
1395                            session = openSession();
1396    
1397                            MembershipRequest[] array = new MembershipRequestImpl[3];
1398    
1399                            array[0] = getByG_S_PrevAndNext(session, membershipRequest,
1400                                            groupId, statusId, orderByComparator, true);
1401    
1402                            array[1] = membershipRequest;
1403    
1404                            array[2] = getByG_S_PrevAndNext(session, membershipRequest,
1405                                            groupId, statusId, orderByComparator, false);
1406    
1407                            return array;
1408                    }
1409                    catch (Exception e) {
1410                            throw processException(e);
1411                    }
1412                    finally {
1413                            closeSession(session);
1414                    }
1415            }
1416    
1417            protected MembershipRequest getByG_S_PrevAndNext(Session session,
1418                    MembershipRequest membershipRequest, long groupId, int statusId,
1419                    OrderByComparator orderByComparator, boolean previous) {
1420                    StringBundler query = null;
1421    
1422                    if (orderByComparator != null) {
1423                            query = new StringBundler(6 +
1424                                            (orderByComparator.getOrderByFields().length * 6));
1425                    }
1426                    else {
1427                            query = new StringBundler(3);
1428                    }
1429    
1430                    query.append(_SQL_SELECT_MEMBERSHIPREQUEST_WHERE);
1431    
1432                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1433    
1434                    query.append(_FINDER_COLUMN_G_S_STATUSID_2);
1435    
1436                    if (orderByComparator != null) {
1437                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1438    
1439                            if (orderByConditionFields.length > 0) {
1440                                    query.append(WHERE_AND);
1441                            }
1442    
1443                            for (int i = 0; i < orderByConditionFields.length; i++) {
1444                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1445                                    query.append(orderByConditionFields[i]);
1446    
1447                                    if ((i + 1) < orderByConditionFields.length) {
1448                                            if (orderByComparator.isAscending() ^ previous) {
1449                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1450                                            }
1451                                            else {
1452                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1453                                            }
1454                                    }
1455                                    else {
1456                                            if (orderByComparator.isAscending() ^ previous) {
1457                                                    query.append(WHERE_GREATER_THAN);
1458                                            }
1459                                            else {
1460                                                    query.append(WHERE_LESSER_THAN);
1461                                            }
1462                                    }
1463                            }
1464    
1465                            query.append(ORDER_BY_CLAUSE);
1466    
1467                            String[] orderByFields = orderByComparator.getOrderByFields();
1468    
1469                            for (int i = 0; i < orderByFields.length; i++) {
1470                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1471                                    query.append(orderByFields[i]);
1472    
1473                                    if ((i + 1) < orderByFields.length) {
1474                                            if (orderByComparator.isAscending() ^ previous) {
1475                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1476                                            }
1477                                            else {
1478                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1479                                            }
1480                                    }
1481                                    else {
1482                                            if (orderByComparator.isAscending() ^ previous) {
1483                                                    query.append(ORDER_BY_ASC);
1484                                            }
1485                                            else {
1486                                                    query.append(ORDER_BY_DESC);
1487                                            }
1488                                    }
1489                            }
1490                    }
1491                    else {
1492                            query.append(MembershipRequestModelImpl.ORDER_BY_JPQL);
1493                    }
1494    
1495                    String sql = query.toString();
1496    
1497                    Query q = session.createQuery(sql);
1498    
1499                    q.setFirstResult(0);
1500                    q.setMaxResults(2);
1501    
1502                    QueryPos qPos = QueryPos.getInstance(q);
1503    
1504                    qPos.add(groupId);
1505    
1506                    qPos.add(statusId);
1507    
1508                    if (orderByComparator != null) {
1509                            Object[] values = orderByComparator.getOrderByConditionValues(membershipRequest);
1510    
1511                            for (Object value : values) {
1512                                    qPos.add(value);
1513                            }
1514                    }
1515    
1516                    List<MembershipRequest> list = q.list();
1517    
1518                    if (list.size() == 2) {
1519                            return list.get(1);
1520                    }
1521                    else {
1522                            return null;
1523                    }
1524            }
1525    
1526            /**
1527             * Removes all the membership requests where groupId = &#63; and statusId = &#63; from the database.
1528             *
1529             * @param groupId the group ID
1530             * @param statusId the status ID
1531             * @throws SystemException if a system exception occurred
1532             */
1533            @Override
1534            public void removeByG_S(long groupId, int statusId)
1535                    throws SystemException {
1536                    for (MembershipRequest membershipRequest : findByG_S(groupId, statusId,
1537                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1538                            remove(membershipRequest);
1539                    }
1540            }
1541    
1542            /**
1543             * Returns the number of membership requests where groupId = &#63; and statusId = &#63;.
1544             *
1545             * @param groupId the group ID
1546             * @param statusId the status ID
1547             * @return the number of matching membership requests
1548             * @throws SystemException if a system exception occurred
1549             */
1550            @Override
1551            public int countByG_S(long groupId, int statusId) throws SystemException {
1552                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
1553    
1554                    Object[] finderArgs = new Object[] { groupId, statusId };
1555    
1556                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1557                                    this);
1558    
1559                    if (count == null) {
1560                            StringBundler query = new StringBundler(3);
1561    
1562                            query.append(_SQL_COUNT_MEMBERSHIPREQUEST_WHERE);
1563    
1564                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1565    
1566                            query.append(_FINDER_COLUMN_G_S_STATUSID_2);
1567    
1568                            String sql = query.toString();
1569    
1570                            Session session = null;
1571    
1572                            try {
1573                                    session = openSession();
1574    
1575                                    Query q = session.createQuery(sql);
1576    
1577                                    QueryPos qPos = QueryPos.getInstance(q);
1578    
1579                                    qPos.add(groupId);
1580    
1581                                    qPos.add(statusId);
1582    
1583                                    count = (Long)q.uniqueResult();
1584    
1585                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1586                            }
1587                            catch (Exception e) {
1588                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1589    
1590                                    throw processException(e);
1591                            }
1592                            finally {
1593                                    closeSession(session);
1594                            }
1595                    }
1596    
1597                    return count.intValue();
1598            }
1599    
1600            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "membershipRequest.groupId = ? AND ";
1601            private static final String _FINDER_COLUMN_G_S_STATUSID_2 = "membershipRequest.statusId = ?";
1602            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
1603                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
1604                            MembershipRequestImpl.class,
1605                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
1606                            new String[] {
1607                                    Long.class.getName(), Long.class.getName(),
1608                                    Integer.class.getName(),
1609                                    
1610                            Integer.class.getName(), Integer.class.getName(),
1611                                    OrderByComparator.class.getName()
1612                            });
1613            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
1614                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED,
1615                            MembershipRequestImpl.class,
1616                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
1617                            new String[] {
1618                                    Long.class.getName(), Long.class.getName(),
1619                                    Integer.class.getName()
1620                            },
1621                            MembershipRequestModelImpl.GROUPID_COLUMN_BITMASK |
1622                            MembershipRequestModelImpl.USERID_COLUMN_BITMASK |
1623                            MembershipRequestModelImpl.STATUSID_COLUMN_BITMASK |
1624                            MembershipRequestModelImpl.CREATEDATE_COLUMN_BITMASK);
1625            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
1626                            MembershipRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
1627                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
1628                            new String[] {
1629                                    Long.class.getName(), Long.class.getName(),
1630                                    Integer.class.getName()
1631                            });
1632    
1633            /**
1634             * Returns all the membership requests where groupId = &#63; and userId = &#63; and statusId = &#63;.
1635             *
1636             * @param groupId the group ID
1637             * @param userId the user ID
1638             * @param statusId the status ID
1639             * @return the matching membership requests
1640             * @throws SystemException if a system exception occurred
1641             */
1642            @Override
1643            public List<MembershipRequest> findByG_U_S(long groupId, long userId,
1644                    int statusId) throws SystemException {
1645                    return findByG_U_S(groupId, userId, statusId, QueryUtil.ALL_POS,
1646                            QueryUtil.ALL_POS, null);
1647            }
1648    
1649            /**
1650             * Returns a range of all the membership requests where groupId = &#63; and userId = &#63; and statusId = &#63;.
1651             *
1652             * <p>
1653             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
1654             * </p>
1655             *
1656             * @param groupId the group ID
1657             * @param userId the user ID
1658             * @param statusId the status ID
1659             * @param start the lower bound of the range of membership requests
1660             * @param end the upper bound of the range of membership requests (not inclusive)
1661             * @return the range of matching membership requests
1662             * @throws SystemException if a system exception occurred
1663             */
1664            @Override
1665            public List<MembershipRequest> findByG_U_S(long groupId, long userId,
1666                    int statusId, int start, int end) throws SystemException {
1667                    return findByG_U_S(groupId, userId, statusId, start, end, null);
1668            }
1669    
1670            /**
1671             * Returns an ordered range of all the membership requests where groupId = &#63; and userId = &#63; and statusId = &#63;.
1672             *
1673             * <p>
1674             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
1675             * </p>
1676             *
1677             * @param groupId the group ID
1678             * @param userId the user ID
1679             * @param statusId the status ID
1680             * @param start the lower bound of the range of membership requests
1681             * @param end the upper bound of the range of membership requests (not inclusive)
1682             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1683             * @return the ordered range of matching membership requests
1684             * @throws SystemException if a system exception occurred
1685             */
1686            @Override
1687            public List<MembershipRequest> findByG_U_S(long groupId, long userId,
1688                    int statusId, int start, int end, OrderByComparator orderByComparator)
1689                    throws SystemException {
1690                    boolean pagination = true;
1691                    FinderPath finderPath = null;
1692                    Object[] finderArgs = null;
1693    
1694                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1695                                    (orderByComparator == null)) {
1696                            pagination = false;
1697                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
1698                            finderArgs = new Object[] { groupId, userId, statusId };
1699                    }
1700                    else {
1701                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
1702                            finderArgs = new Object[] {
1703                                            groupId, userId, statusId,
1704                                            
1705                                            start, end, orderByComparator
1706                                    };
1707                    }
1708    
1709                    List<MembershipRequest> list = (List<MembershipRequest>)FinderCacheUtil.getResult(finderPath,
1710                                    finderArgs, this);
1711    
1712                    if ((list != null) && !list.isEmpty()) {
1713                            for (MembershipRequest membershipRequest : list) {
1714                                    if ((groupId != membershipRequest.getGroupId()) ||
1715                                                    (userId != membershipRequest.getUserId()) ||
1716                                                    (statusId != membershipRequest.getStatusId())) {
1717                                            list = null;
1718    
1719                                            break;
1720                                    }
1721                            }
1722                    }
1723    
1724                    if (list == null) {
1725                            StringBundler query = null;
1726    
1727                            if (orderByComparator != null) {
1728                                    query = new StringBundler(5 +
1729                                                    (orderByComparator.getOrderByFields().length * 3));
1730                            }
1731                            else {
1732                                    query = new StringBundler(5);
1733                            }
1734    
1735                            query.append(_SQL_SELECT_MEMBERSHIPREQUEST_WHERE);
1736    
1737                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
1738    
1739                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
1740    
1741                            query.append(_FINDER_COLUMN_G_U_S_STATUSID_2);
1742    
1743                            if (orderByComparator != null) {
1744                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1745                                            orderByComparator);
1746                            }
1747                            else
1748                             if (pagination) {
1749                                    query.append(MembershipRequestModelImpl.ORDER_BY_JPQL);
1750                            }
1751    
1752                            String sql = query.toString();
1753    
1754                            Session session = null;
1755    
1756                            try {
1757                                    session = openSession();
1758    
1759                                    Query q = session.createQuery(sql);
1760    
1761                                    QueryPos qPos = QueryPos.getInstance(q);
1762    
1763                                    qPos.add(groupId);
1764    
1765                                    qPos.add(userId);
1766    
1767                                    qPos.add(statusId);
1768    
1769                                    if (!pagination) {
1770                                            list = (List<MembershipRequest>)QueryUtil.list(q,
1771                                                            getDialect(), start, end, false);
1772    
1773                                            Collections.sort(list);
1774    
1775                                            list = new UnmodifiableList<MembershipRequest>(list);
1776                                    }
1777                                    else {
1778                                            list = (List<MembershipRequest>)QueryUtil.list(q,
1779                                                            getDialect(), start, end);
1780                                    }
1781    
1782                                    cacheResult(list);
1783    
1784                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1785                            }
1786                            catch (Exception e) {
1787                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1788    
1789                                    throw processException(e);
1790                            }
1791                            finally {
1792                                    closeSession(session);
1793                            }
1794                    }
1795    
1796                    return list;
1797            }
1798    
1799            /**
1800             * Returns the first membership request in the ordered set where groupId = &#63; and userId = &#63; and statusId = &#63;.
1801             *
1802             * @param groupId the group ID
1803             * @param userId the user ID
1804             * @param statusId the status ID
1805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1806             * @return the first matching membership request
1807             * @throws com.liferay.portal.NoSuchMembershipRequestException if a matching membership request could not be found
1808             * @throws SystemException if a system exception occurred
1809             */
1810            @Override
1811            public MembershipRequest findByG_U_S_First(long groupId, long userId,
1812                    int statusId, OrderByComparator orderByComparator)
1813                    throws NoSuchMembershipRequestException, SystemException {
1814                    MembershipRequest membershipRequest = fetchByG_U_S_First(groupId,
1815                                    userId, statusId, orderByComparator);
1816    
1817                    if (membershipRequest != null) {
1818                            return membershipRequest;
1819                    }
1820    
1821                    StringBundler msg = new StringBundler(8);
1822    
1823                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1824    
1825                    msg.append("groupId=");
1826                    msg.append(groupId);
1827    
1828                    msg.append(", userId=");
1829                    msg.append(userId);
1830    
1831                    msg.append(", statusId=");
1832                    msg.append(statusId);
1833    
1834                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1835    
1836                    throw new NoSuchMembershipRequestException(msg.toString());
1837            }
1838    
1839            /**
1840             * Returns the first membership request in the ordered set where groupId = &#63; and userId = &#63; and statusId = &#63;.
1841             *
1842             * @param groupId the group ID
1843             * @param userId the user ID
1844             * @param statusId the status ID
1845             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1846             * @return the first matching membership request, or <code>null</code> if a matching membership request could not be found
1847             * @throws SystemException if a system exception occurred
1848             */
1849            @Override
1850            public MembershipRequest fetchByG_U_S_First(long groupId, long userId,
1851                    int statusId, OrderByComparator orderByComparator)
1852                    throws SystemException {
1853                    List<MembershipRequest> list = findByG_U_S(groupId, userId, statusId,
1854                                    0, 1, orderByComparator);
1855    
1856                    if (!list.isEmpty()) {
1857                            return list.get(0);
1858                    }
1859    
1860                    return null;
1861            }
1862    
1863            /**
1864             * Returns the last membership request in the ordered set where groupId = &#63; and userId = &#63; and statusId = &#63;.
1865             *
1866             * @param groupId the group ID
1867             * @param userId the user ID
1868             * @param statusId the status ID
1869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1870             * @return the last matching membership request
1871             * @throws com.liferay.portal.NoSuchMembershipRequestException if a matching membership request could not be found
1872             * @throws SystemException if a system exception occurred
1873             */
1874            @Override
1875            public MembershipRequest findByG_U_S_Last(long groupId, long userId,
1876                    int statusId, OrderByComparator orderByComparator)
1877                    throws NoSuchMembershipRequestException, SystemException {
1878                    MembershipRequest membershipRequest = fetchByG_U_S_Last(groupId,
1879                                    userId, statusId, orderByComparator);
1880    
1881                    if (membershipRequest != null) {
1882                            return membershipRequest;
1883                    }
1884    
1885                    StringBundler msg = new StringBundler(8);
1886    
1887                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1888    
1889                    msg.append("groupId=");
1890                    msg.append(groupId);
1891    
1892                    msg.append(", userId=");
1893                    msg.append(userId);
1894    
1895                    msg.append(", statusId=");
1896                    msg.append(statusId);
1897    
1898                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1899    
1900                    throw new NoSuchMembershipRequestException(msg.toString());
1901            }
1902    
1903            /**
1904             * Returns the last membership request in the ordered set where groupId = &#63; and userId = &#63; and statusId = &#63;.
1905             *
1906             * @param groupId the group ID
1907             * @param userId the user ID
1908             * @param statusId the status ID
1909             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1910             * @return the last matching membership request, or <code>null</code> if a matching membership request could not be found
1911             * @throws SystemException if a system exception occurred
1912             */
1913            @Override
1914            public MembershipRequest fetchByG_U_S_Last(long groupId, long userId,
1915                    int statusId, OrderByComparator orderByComparator)
1916                    throws SystemException {
1917                    int count = countByG_U_S(groupId, userId, statusId);
1918    
1919                    if (count == 0) {
1920                            return null;
1921                    }
1922    
1923                    List<MembershipRequest> list = findByG_U_S(groupId, userId, statusId,
1924                                    count - 1, count, orderByComparator);
1925    
1926                    if (!list.isEmpty()) {
1927                            return list.get(0);
1928                    }
1929    
1930                    return null;
1931            }
1932    
1933            /**
1934             * Returns the membership requests before and after the current membership request in the ordered set where groupId = &#63; and userId = &#63; and statusId = &#63;.
1935             *
1936             * @param membershipRequestId the primary key of the current membership request
1937             * @param groupId the group ID
1938             * @param userId the user ID
1939             * @param statusId the status ID
1940             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1941             * @return the previous, current, and next membership request
1942             * @throws com.liferay.portal.NoSuchMembershipRequestException if a membership request with the primary key could not be found
1943             * @throws SystemException if a system exception occurred
1944             */
1945            @Override
1946            public MembershipRequest[] findByG_U_S_PrevAndNext(
1947                    long membershipRequestId, long groupId, long userId, int statusId,
1948                    OrderByComparator orderByComparator)
1949                    throws NoSuchMembershipRequestException, SystemException {
1950                    MembershipRequest membershipRequest = findByPrimaryKey(membershipRequestId);
1951    
1952                    Session session = null;
1953    
1954                    try {
1955                            session = openSession();
1956    
1957                            MembershipRequest[] array = new MembershipRequestImpl[3];
1958    
1959                            array[0] = getByG_U_S_PrevAndNext(session, membershipRequest,
1960                                            groupId, userId, statusId, orderByComparator, true);
1961    
1962                            array[1] = membershipRequest;
1963    
1964                            array[2] = getByG_U_S_PrevAndNext(session, membershipRequest,
1965                                            groupId, userId, statusId, orderByComparator, false);
1966    
1967                            return array;
1968                    }
1969                    catch (Exception e) {
1970                            throw processException(e);
1971                    }
1972                    finally {
1973                            closeSession(session);
1974                    }
1975            }
1976    
1977            protected MembershipRequest getByG_U_S_PrevAndNext(Session session,
1978                    MembershipRequest membershipRequest, long groupId, long userId,
1979                    int statusId, OrderByComparator orderByComparator, boolean previous) {
1980                    StringBundler query = null;
1981    
1982                    if (orderByComparator != null) {
1983                            query = new StringBundler(6 +
1984                                            (orderByComparator.getOrderByFields().length * 6));
1985                    }
1986                    else {
1987                            query = new StringBundler(3);
1988                    }
1989    
1990                    query.append(_SQL_SELECT_MEMBERSHIPREQUEST_WHERE);
1991    
1992                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
1993    
1994                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
1995    
1996                    query.append(_FINDER_COLUMN_G_U_S_STATUSID_2);
1997    
1998                    if (orderByComparator != null) {
1999                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2000    
2001                            if (orderByConditionFields.length > 0) {
2002                                    query.append(WHERE_AND);
2003                            }
2004    
2005                            for (int i = 0; i < orderByConditionFields.length; i++) {
2006                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2007                                    query.append(orderByConditionFields[i]);
2008    
2009                                    if ((i + 1) < orderByConditionFields.length) {
2010                                            if (orderByComparator.isAscending() ^ previous) {
2011                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2012                                            }
2013                                            else {
2014                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2015                                            }
2016                                    }
2017                                    else {
2018                                            if (orderByComparator.isAscending() ^ previous) {
2019                                                    query.append(WHERE_GREATER_THAN);
2020                                            }
2021                                            else {
2022                                                    query.append(WHERE_LESSER_THAN);
2023                                            }
2024                                    }
2025                            }
2026    
2027                            query.append(ORDER_BY_CLAUSE);
2028    
2029                            String[] orderByFields = orderByComparator.getOrderByFields();
2030    
2031                            for (int i = 0; i < orderByFields.length; i++) {
2032                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2033                                    query.append(orderByFields[i]);
2034    
2035                                    if ((i + 1) < orderByFields.length) {
2036                                            if (orderByComparator.isAscending() ^ previous) {
2037                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2038                                            }
2039                                            else {
2040                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2041                                            }
2042                                    }
2043                                    else {
2044                                            if (orderByComparator.isAscending() ^ previous) {
2045                                                    query.append(ORDER_BY_ASC);
2046                                            }
2047                                            else {
2048                                                    query.append(ORDER_BY_DESC);
2049                                            }
2050                                    }
2051                            }
2052                    }
2053                    else {
2054                            query.append(MembershipRequestModelImpl.ORDER_BY_JPQL);
2055                    }
2056    
2057                    String sql = query.toString();
2058    
2059                    Query q = session.createQuery(sql);
2060    
2061                    q.setFirstResult(0);
2062                    q.setMaxResults(2);
2063    
2064                    QueryPos qPos = QueryPos.getInstance(q);
2065    
2066                    qPos.add(groupId);
2067    
2068                    qPos.add(userId);
2069    
2070                    qPos.add(statusId);
2071    
2072                    if (orderByComparator != null) {
2073                            Object[] values = orderByComparator.getOrderByConditionValues(membershipRequest);
2074    
2075                            for (Object value : values) {
2076                                    qPos.add(value);
2077                            }
2078                    }
2079    
2080                    List<MembershipRequest> list = q.list();
2081    
2082                    if (list.size() == 2) {
2083                            return list.get(1);
2084                    }
2085                    else {
2086                            return null;
2087                    }
2088            }
2089    
2090            /**
2091             * Removes all the membership requests where groupId = &#63; and userId = &#63; and statusId = &#63; from the database.
2092             *
2093             * @param groupId the group ID
2094             * @param userId the user ID
2095             * @param statusId the status ID
2096             * @throws SystemException if a system exception occurred
2097             */
2098            @Override
2099            public void removeByG_U_S(long groupId, long userId, int statusId)
2100                    throws SystemException {
2101                    for (MembershipRequest membershipRequest : findByG_U_S(groupId, userId,
2102                                    statusId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2103                            remove(membershipRequest);
2104                    }
2105            }
2106    
2107            /**
2108             * Returns the number of membership requests where groupId = &#63; and userId = &#63; and statusId = &#63;.
2109             *
2110             * @param groupId the group ID
2111             * @param userId the user ID
2112             * @param statusId the status ID
2113             * @return the number of matching membership requests
2114             * @throws SystemException if a system exception occurred
2115             */
2116            @Override
2117            public int countByG_U_S(long groupId, long userId, int statusId)
2118                    throws SystemException {
2119                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
2120    
2121                    Object[] finderArgs = new Object[] { groupId, userId, statusId };
2122    
2123                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2124                                    this);
2125    
2126                    if (count == null) {
2127                            StringBundler query = new StringBundler(4);
2128    
2129                            query.append(_SQL_COUNT_MEMBERSHIPREQUEST_WHERE);
2130    
2131                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
2132    
2133                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
2134    
2135                            query.append(_FINDER_COLUMN_G_U_S_STATUSID_2);
2136    
2137                            String sql = query.toString();
2138    
2139                            Session session = null;
2140    
2141                            try {
2142                                    session = openSession();
2143    
2144                                    Query q = session.createQuery(sql);
2145    
2146                                    QueryPos qPos = QueryPos.getInstance(q);
2147    
2148                                    qPos.add(groupId);
2149    
2150                                    qPos.add(userId);
2151    
2152                                    qPos.add(statusId);
2153    
2154                                    count = (Long)q.uniqueResult();
2155    
2156                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2157                            }
2158                            catch (Exception e) {
2159                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2160    
2161                                    throw processException(e);
2162                            }
2163                            finally {
2164                                    closeSession(session);
2165                            }
2166                    }
2167    
2168                    return count.intValue();
2169            }
2170    
2171            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "membershipRequest.groupId = ? AND ";
2172            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "membershipRequest.userId = ? AND ";
2173            private static final String _FINDER_COLUMN_G_U_S_STATUSID_2 = "membershipRequest.statusId = ?";
2174    
2175            public MembershipRequestPersistenceImpl() {
2176                    setModelClass(MembershipRequest.class);
2177            }
2178    
2179            /**
2180             * Caches the membership request in the entity cache if it is enabled.
2181             *
2182             * @param membershipRequest the membership request
2183             */
2184            @Override
2185            public void cacheResult(MembershipRequest membershipRequest) {
2186                    EntityCacheUtil.putResult(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
2187                            MembershipRequestImpl.class, membershipRequest.getPrimaryKey(),
2188                            membershipRequest);
2189    
2190                    membershipRequest.resetOriginalValues();
2191            }
2192    
2193            /**
2194             * Caches the membership requests in the entity cache if it is enabled.
2195             *
2196             * @param membershipRequests the membership requests
2197             */
2198            @Override
2199            public void cacheResult(List<MembershipRequest> membershipRequests) {
2200                    for (MembershipRequest membershipRequest : membershipRequests) {
2201                            if (EntityCacheUtil.getResult(
2202                                                    MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
2203                                                    MembershipRequestImpl.class,
2204                                                    membershipRequest.getPrimaryKey()) == null) {
2205                                    cacheResult(membershipRequest);
2206                            }
2207                            else {
2208                                    membershipRequest.resetOriginalValues();
2209                            }
2210                    }
2211            }
2212    
2213            /**
2214             * Clears the cache for all membership requests.
2215             *
2216             * <p>
2217             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2218             * </p>
2219             */
2220            @Override
2221            public void clearCache() {
2222                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2223                            CacheRegistryUtil.clear(MembershipRequestImpl.class.getName());
2224                    }
2225    
2226                    EntityCacheUtil.clearCache(MembershipRequestImpl.class.getName());
2227    
2228                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2229                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2230                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2231            }
2232    
2233            /**
2234             * Clears the cache for the membership request.
2235             *
2236             * <p>
2237             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
2238             * </p>
2239             */
2240            @Override
2241            public void clearCache(MembershipRequest membershipRequest) {
2242                    EntityCacheUtil.removeResult(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
2243                            MembershipRequestImpl.class, membershipRequest.getPrimaryKey());
2244    
2245                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2246                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2247            }
2248    
2249            @Override
2250            public void clearCache(List<MembershipRequest> membershipRequests) {
2251                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2252                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2253    
2254                    for (MembershipRequest membershipRequest : membershipRequests) {
2255                            EntityCacheUtil.removeResult(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
2256                                    MembershipRequestImpl.class, membershipRequest.getPrimaryKey());
2257                    }
2258            }
2259    
2260            /**
2261             * Creates a new membership request with the primary key. Does not add the membership request to the database.
2262             *
2263             * @param membershipRequestId the primary key for the new membership request
2264             * @return the new membership request
2265             */
2266            @Override
2267            public MembershipRequest create(long membershipRequestId) {
2268                    MembershipRequest membershipRequest = new MembershipRequestImpl();
2269    
2270                    membershipRequest.setNew(true);
2271                    membershipRequest.setPrimaryKey(membershipRequestId);
2272    
2273                    return membershipRequest;
2274            }
2275    
2276            /**
2277             * Removes the membership request with the primary key from the database. Also notifies the appropriate model listeners.
2278             *
2279             * @param membershipRequestId the primary key of the membership request
2280             * @return the membership request that was removed
2281             * @throws com.liferay.portal.NoSuchMembershipRequestException if a membership request with the primary key could not be found
2282             * @throws SystemException if a system exception occurred
2283             */
2284            @Override
2285            public MembershipRequest remove(long membershipRequestId)
2286                    throws NoSuchMembershipRequestException, SystemException {
2287                    return remove((Serializable)membershipRequestId);
2288            }
2289    
2290            /**
2291             * Removes the membership request with the primary key from the database. Also notifies the appropriate model listeners.
2292             *
2293             * @param primaryKey the primary key of the membership request
2294             * @return the membership request that was removed
2295             * @throws com.liferay.portal.NoSuchMembershipRequestException if a membership request with the primary key could not be found
2296             * @throws SystemException if a system exception occurred
2297             */
2298            @Override
2299            public MembershipRequest remove(Serializable primaryKey)
2300                    throws NoSuchMembershipRequestException, SystemException {
2301                    Session session = null;
2302    
2303                    try {
2304                            session = openSession();
2305    
2306                            MembershipRequest membershipRequest = (MembershipRequest)session.get(MembershipRequestImpl.class,
2307                                            primaryKey);
2308    
2309                            if (membershipRequest == null) {
2310                                    if (_log.isWarnEnabled()) {
2311                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2312                                    }
2313    
2314                                    throw new NoSuchMembershipRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2315                                            primaryKey);
2316                            }
2317    
2318                            return remove(membershipRequest);
2319                    }
2320                    catch (NoSuchMembershipRequestException nsee) {
2321                            throw nsee;
2322                    }
2323                    catch (Exception e) {
2324                            throw processException(e);
2325                    }
2326                    finally {
2327                            closeSession(session);
2328                    }
2329            }
2330    
2331            @Override
2332            protected MembershipRequest removeImpl(MembershipRequest membershipRequest)
2333                    throws SystemException {
2334                    membershipRequest = toUnwrappedModel(membershipRequest);
2335    
2336                    Session session = null;
2337    
2338                    try {
2339                            session = openSession();
2340    
2341                            if (!session.contains(membershipRequest)) {
2342                                    membershipRequest = (MembershipRequest)session.get(MembershipRequestImpl.class,
2343                                                    membershipRequest.getPrimaryKeyObj());
2344                            }
2345    
2346                            if (membershipRequest != null) {
2347                                    session.delete(membershipRequest);
2348                            }
2349                    }
2350                    catch (Exception e) {
2351                            throw processException(e);
2352                    }
2353                    finally {
2354                            closeSession(session);
2355                    }
2356    
2357                    if (membershipRequest != null) {
2358                            clearCache(membershipRequest);
2359                    }
2360    
2361                    return membershipRequest;
2362            }
2363    
2364            @Override
2365            public MembershipRequest updateImpl(
2366                    com.liferay.portal.model.MembershipRequest membershipRequest)
2367                    throws SystemException {
2368                    membershipRequest = toUnwrappedModel(membershipRequest);
2369    
2370                    boolean isNew = membershipRequest.isNew();
2371    
2372                    MembershipRequestModelImpl membershipRequestModelImpl = (MembershipRequestModelImpl)membershipRequest;
2373    
2374                    Session session = null;
2375    
2376                    try {
2377                            session = openSession();
2378    
2379                            if (membershipRequest.isNew()) {
2380                                    session.save(membershipRequest);
2381    
2382                                    membershipRequest.setNew(false);
2383                            }
2384                            else {
2385                                    session.merge(membershipRequest);
2386                            }
2387                    }
2388                    catch (Exception e) {
2389                            throw processException(e);
2390                    }
2391                    finally {
2392                            closeSession(session);
2393                    }
2394    
2395                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2396    
2397                    if (isNew || !MembershipRequestModelImpl.COLUMN_BITMASK_ENABLED) {
2398                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2399                    }
2400    
2401                    else {
2402                            if ((membershipRequestModelImpl.getColumnBitmask() &
2403                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2404                                    Object[] args = new Object[] {
2405                                                    membershipRequestModelImpl.getOriginalGroupId()
2406                                            };
2407    
2408                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2409                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2410                                            args);
2411    
2412                                    args = new Object[] { membershipRequestModelImpl.getGroupId() };
2413    
2414                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2415                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2416                                            args);
2417                            }
2418    
2419                            if ((membershipRequestModelImpl.getColumnBitmask() &
2420                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2421                                    Object[] args = new Object[] {
2422                                                    membershipRequestModelImpl.getOriginalUserId()
2423                                            };
2424    
2425                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2426                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2427                                            args);
2428    
2429                                    args = new Object[] { membershipRequestModelImpl.getUserId() };
2430    
2431                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2432                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2433                                            args);
2434                            }
2435    
2436                            if ((membershipRequestModelImpl.getColumnBitmask() &
2437                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
2438                                    Object[] args = new Object[] {
2439                                                    membershipRequestModelImpl.getOriginalGroupId(),
2440                                                    membershipRequestModelImpl.getOriginalStatusId()
2441                                            };
2442    
2443                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
2444                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
2445                                            args);
2446    
2447                                    args = new Object[] {
2448                                                    membershipRequestModelImpl.getGroupId(),
2449                                                    membershipRequestModelImpl.getStatusId()
2450                                            };
2451    
2452                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
2453                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
2454                                            args);
2455                            }
2456    
2457                            if ((membershipRequestModelImpl.getColumnBitmask() &
2458                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
2459                                    Object[] args = new Object[] {
2460                                                    membershipRequestModelImpl.getOriginalGroupId(),
2461                                                    membershipRequestModelImpl.getOriginalUserId(),
2462                                                    membershipRequestModelImpl.getOriginalStatusId()
2463                                            };
2464    
2465                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
2466                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
2467                                            args);
2468    
2469                                    args = new Object[] {
2470                                                    membershipRequestModelImpl.getGroupId(),
2471                                                    membershipRequestModelImpl.getUserId(),
2472                                                    membershipRequestModelImpl.getStatusId()
2473                                            };
2474    
2475                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
2476                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
2477                                            args);
2478                            }
2479                    }
2480    
2481                    EntityCacheUtil.putResult(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
2482                            MembershipRequestImpl.class, membershipRequest.getPrimaryKey(),
2483                            membershipRequest);
2484    
2485                    return membershipRequest;
2486            }
2487    
2488            protected MembershipRequest toUnwrappedModel(
2489                    MembershipRequest membershipRequest) {
2490                    if (membershipRequest instanceof MembershipRequestImpl) {
2491                            return membershipRequest;
2492                    }
2493    
2494                    MembershipRequestImpl membershipRequestImpl = new MembershipRequestImpl();
2495    
2496                    membershipRequestImpl.setNew(membershipRequest.isNew());
2497                    membershipRequestImpl.setPrimaryKey(membershipRequest.getPrimaryKey());
2498    
2499                    membershipRequestImpl.setMembershipRequestId(membershipRequest.getMembershipRequestId());
2500                    membershipRequestImpl.setGroupId(membershipRequest.getGroupId());
2501                    membershipRequestImpl.setCompanyId(membershipRequest.getCompanyId());
2502                    membershipRequestImpl.setUserId(membershipRequest.getUserId());
2503                    membershipRequestImpl.setCreateDate(membershipRequest.getCreateDate());
2504                    membershipRequestImpl.setComments(membershipRequest.getComments());
2505                    membershipRequestImpl.setReplyComments(membershipRequest.getReplyComments());
2506                    membershipRequestImpl.setReplyDate(membershipRequest.getReplyDate());
2507                    membershipRequestImpl.setReplierUserId(membershipRequest.getReplierUserId());
2508                    membershipRequestImpl.setStatusId(membershipRequest.getStatusId());
2509    
2510                    return membershipRequestImpl;
2511            }
2512    
2513            /**
2514             * Returns the membership request with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
2515             *
2516             * @param primaryKey the primary key of the membership request
2517             * @return the membership request
2518             * @throws com.liferay.portal.NoSuchMembershipRequestException if a membership request with the primary key could not be found
2519             * @throws SystemException if a system exception occurred
2520             */
2521            @Override
2522            public MembershipRequest findByPrimaryKey(Serializable primaryKey)
2523                    throws NoSuchMembershipRequestException, SystemException {
2524                    MembershipRequest membershipRequest = fetchByPrimaryKey(primaryKey);
2525    
2526                    if (membershipRequest == null) {
2527                            if (_log.isWarnEnabled()) {
2528                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2529                            }
2530    
2531                            throw new NoSuchMembershipRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2532                                    primaryKey);
2533                    }
2534    
2535                    return membershipRequest;
2536            }
2537    
2538            /**
2539             * Returns the membership request with the primary key or throws a {@link com.liferay.portal.NoSuchMembershipRequestException} if it could not be found.
2540             *
2541             * @param membershipRequestId the primary key of the membership request
2542             * @return the membership request
2543             * @throws com.liferay.portal.NoSuchMembershipRequestException if a membership request with the primary key could not be found
2544             * @throws SystemException if a system exception occurred
2545             */
2546            @Override
2547            public MembershipRequest findByPrimaryKey(long membershipRequestId)
2548                    throws NoSuchMembershipRequestException, SystemException {
2549                    return findByPrimaryKey((Serializable)membershipRequestId);
2550            }
2551    
2552            /**
2553             * Returns the membership request with the primary key or returns <code>null</code> if it could not be found.
2554             *
2555             * @param primaryKey the primary key of the membership request
2556             * @return the membership request, or <code>null</code> if a membership request with the primary key could not be found
2557             * @throws SystemException if a system exception occurred
2558             */
2559            @Override
2560            public MembershipRequest fetchByPrimaryKey(Serializable primaryKey)
2561                    throws SystemException {
2562                    MembershipRequest membershipRequest = (MembershipRequest)EntityCacheUtil.getResult(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
2563                                    MembershipRequestImpl.class, primaryKey);
2564    
2565                    if (membershipRequest == _nullMembershipRequest) {
2566                            return null;
2567                    }
2568    
2569                    if (membershipRequest == null) {
2570                            Session session = null;
2571    
2572                            try {
2573                                    session = openSession();
2574    
2575                                    membershipRequest = (MembershipRequest)session.get(MembershipRequestImpl.class,
2576                                                    primaryKey);
2577    
2578                                    if (membershipRequest != null) {
2579                                            cacheResult(membershipRequest);
2580                                    }
2581                                    else {
2582                                            EntityCacheUtil.putResult(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
2583                                                    MembershipRequestImpl.class, primaryKey,
2584                                                    _nullMembershipRequest);
2585                                    }
2586                            }
2587                            catch (Exception e) {
2588                                    EntityCacheUtil.removeResult(MembershipRequestModelImpl.ENTITY_CACHE_ENABLED,
2589                                            MembershipRequestImpl.class, primaryKey);
2590    
2591                                    throw processException(e);
2592                            }
2593                            finally {
2594                                    closeSession(session);
2595                            }
2596                    }
2597    
2598                    return membershipRequest;
2599            }
2600    
2601            /**
2602             * Returns the membership request with the primary key or returns <code>null</code> if it could not be found.
2603             *
2604             * @param membershipRequestId the primary key of the membership request
2605             * @return the membership request, or <code>null</code> if a membership request with the primary key could not be found
2606             * @throws SystemException if a system exception occurred
2607             */
2608            @Override
2609            public MembershipRequest fetchByPrimaryKey(long membershipRequestId)
2610                    throws SystemException {
2611                    return fetchByPrimaryKey((Serializable)membershipRequestId);
2612            }
2613    
2614            /**
2615             * Returns all the membership requests.
2616             *
2617             * @return the membership requests
2618             * @throws SystemException if a system exception occurred
2619             */
2620            @Override
2621            public List<MembershipRequest> findAll() throws SystemException {
2622                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2623            }
2624    
2625            /**
2626             * Returns a range of all the membership requests.
2627             *
2628             * <p>
2629             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
2630             * </p>
2631             *
2632             * @param start the lower bound of the range of membership requests
2633             * @param end the upper bound of the range of membership requests (not inclusive)
2634             * @return the range of membership requests
2635             * @throws SystemException if a system exception occurred
2636             */
2637            @Override
2638            public List<MembershipRequest> findAll(int start, int end)
2639                    throws SystemException {
2640                    return findAll(start, end, null);
2641            }
2642    
2643            /**
2644             * Returns an ordered range of all the membership requests.
2645             *
2646             * <p>
2647             * 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 com.liferay.portal.kernel.dao.orm.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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.MembershipRequestModelImpl}. 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.
2648             * </p>
2649             *
2650             * @param start the lower bound of the range of membership requests
2651             * @param end the upper bound of the range of membership requests (not inclusive)
2652             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2653             * @return the ordered range of membership requests
2654             * @throws SystemException if a system exception occurred
2655             */
2656            @Override
2657            public List<MembershipRequest> findAll(int start, int end,
2658                    OrderByComparator orderByComparator) throws SystemException {
2659                    boolean pagination = true;
2660                    FinderPath finderPath = null;
2661                    Object[] finderArgs = null;
2662    
2663                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2664                                    (orderByComparator == null)) {
2665                            pagination = false;
2666                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2667                            finderArgs = FINDER_ARGS_EMPTY;
2668                    }
2669                    else {
2670                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2671                            finderArgs = new Object[] { start, end, orderByComparator };
2672                    }
2673    
2674                    List<MembershipRequest> list = (List<MembershipRequest>)FinderCacheUtil.getResult(finderPath,
2675                                    finderArgs, this);
2676    
2677                    if (list == null) {
2678                            StringBundler query = null;
2679                            String sql = null;
2680    
2681                            if (orderByComparator != null) {
2682                                    query = new StringBundler(2 +
2683                                                    (orderByComparator.getOrderByFields().length * 3));
2684    
2685                                    query.append(_SQL_SELECT_MEMBERSHIPREQUEST);
2686    
2687                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2688                                            orderByComparator);
2689    
2690                                    sql = query.toString();
2691                            }
2692                            else {
2693                                    sql = _SQL_SELECT_MEMBERSHIPREQUEST;
2694    
2695                                    if (pagination) {
2696                                            sql = sql.concat(MembershipRequestModelImpl.ORDER_BY_JPQL);
2697                                    }
2698                            }
2699    
2700                            Session session = null;
2701    
2702                            try {
2703                                    session = openSession();
2704    
2705                                    Query q = session.createQuery(sql);
2706    
2707                                    if (!pagination) {
2708                                            list = (List<MembershipRequest>)QueryUtil.list(q,
2709                                                            getDialect(), start, end, false);
2710    
2711                                            Collections.sort(list);
2712    
2713                                            list = new UnmodifiableList<MembershipRequest>(list);
2714                                    }
2715                                    else {
2716                                            list = (List<MembershipRequest>)QueryUtil.list(q,
2717                                                            getDialect(), start, end);
2718                                    }
2719    
2720                                    cacheResult(list);
2721    
2722                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2723                            }
2724                            catch (Exception e) {
2725                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2726    
2727                                    throw processException(e);
2728                            }
2729                            finally {
2730                                    closeSession(session);
2731                            }
2732                    }
2733    
2734                    return list;
2735            }
2736    
2737            /**
2738             * Removes all the membership requests from the database.
2739             *
2740             * @throws SystemException if a system exception occurred
2741             */
2742            @Override
2743            public void removeAll() throws SystemException {
2744                    for (MembershipRequest membershipRequest : findAll()) {
2745                            remove(membershipRequest);
2746                    }
2747            }
2748    
2749            /**
2750             * Returns the number of membership requests.
2751             *
2752             * @return the number of membership requests
2753             * @throws SystemException if a system exception occurred
2754             */
2755            @Override
2756            public int countAll() throws SystemException {
2757                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2758                                    FINDER_ARGS_EMPTY, this);
2759    
2760                    if (count == null) {
2761                            Session session = null;
2762    
2763                            try {
2764                                    session = openSession();
2765    
2766                                    Query q = session.createQuery(_SQL_COUNT_MEMBERSHIPREQUEST);
2767    
2768                                    count = (Long)q.uniqueResult();
2769    
2770                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2771                                            FINDER_ARGS_EMPTY, count);
2772                            }
2773                            catch (Exception e) {
2774                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2775                                            FINDER_ARGS_EMPTY);
2776    
2777                                    throw processException(e);
2778                            }
2779                            finally {
2780                                    closeSession(session);
2781                            }
2782                    }
2783    
2784                    return count.intValue();
2785            }
2786    
2787            /**
2788             * Initializes the membership request persistence.
2789             */
2790            public void afterPropertiesSet() {
2791                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2792                                            com.liferay.portal.util.PropsUtil.get(
2793                                                    "value.object.listener.com.liferay.portal.model.MembershipRequest")));
2794    
2795                    if (listenerClassNames.length > 0) {
2796                            try {
2797                                    List<ModelListener<MembershipRequest>> listenersList = new ArrayList<ModelListener<MembershipRequest>>();
2798    
2799                                    for (String listenerClassName : listenerClassNames) {
2800                                            listenersList.add((ModelListener<MembershipRequest>)InstanceFactory.newInstance(
2801                                                            getClassLoader(), listenerClassName));
2802                                    }
2803    
2804                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2805                            }
2806                            catch (Exception e) {
2807                                    _log.error(e);
2808                            }
2809                    }
2810            }
2811    
2812            public void destroy() {
2813                    EntityCacheUtil.removeCache(MembershipRequestImpl.class.getName());
2814                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2815                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2816                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2817            }
2818    
2819            private static final String _SQL_SELECT_MEMBERSHIPREQUEST = "SELECT membershipRequest FROM MembershipRequest membershipRequest";
2820            private static final String _SQL_SELECT_MEMBERSHIPREQUEST_WHERE = "SELECT membershipRequest FROM MembershipRequest membershipRequest WHERE ";
2821            private static final String _SQL_COUNT_MEMBERSHIPREQUEST = "SELECT COUNT(membershipRequest) FROM MembershipRequest membershipRequest";
2822            private static final String _SQL_COUNT_MEMBERSHIPREQUEST_WHERE = "SELECT COUNT(membershipRequest) FROM MembershipRequest membershipRequest WHERE ";
2823            private static final String _ORDER_BY_ENTITY_ALIAS = "membershipRequest.";
2824            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MembershipRequest exists with the primary key ";
2825            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MembershipRequest exists with the key {";
2826            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2827            private static Log _log = LogFactoryUtil.getLog(MembershipRequestPersistenceImpl.class);
2828            private static MembershipRequest _nullMembershipRequest = new MembershipRequestImpl() {
2829                            @Override
2830                            public Object clone() {
2831                                    return this;
2832                            }
2833    
2834                            @Override
2835                            public CacheModel<MembershipRequest> toCacheModel() {
2836                                    return _nullMembershipRequestCacheModel;
2837                            }
2838                    };
2839    
2840            private static CacheModel<MembershipRequest> _nullMembershipRequestCacheModel =
2841                    new CacheModel<MembershipRequest>() {
2842                            @Override
2843                            public MembershipRequest toEntityModel() {
2844                                    return _nullMembershipRequest;
2845                            }
2846                    };
2847    }