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