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