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