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