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