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