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