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