001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.social.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.model.CacheModel;
032    import com.liferay.portal.kernel.service.persistence.CompanyProvider;
033    import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
034    import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
035    import com.liferay.portal.kernel.util.OrderByComparator;
036    import com.liferay.portal.kernel.util.SetUtil;
037    import com.liferay.portal.kernel.util.StringBundler;
038    import com.liferay.portal.kernel.util.StringPool;
039    import com.liferay.portal.kernel.util.Validator;
040    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
041    
042    import com.liferay.portlet.social.model.impl.SocialRequestImpl;
043    import com.liferay.portlet.social.model.impl.SocialRequestModelImpl;
044    
045    import com.liferay.social.kernel.exception.NoSuchRequestException;
046    import com.liferay.social.kernel.model.SocialRequest;
047    import com.liferay.social.kernel.service.persistence.SocialRequestPersistence;
048    
049    import java.io.Serializable;
050    
051    import java.util.Collections;
052    import java.util.HashMap;
053    import java.util.HashSet;
054    import java.util.Iterator;
055    import java.util.List;
056    import java.util.Map;
057    import java.util.Objects;
058    import java.util.Set;
059    
060    /**
061     * The persistence implementation for the social request service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see SocialRequestPersistence
069     * @see com.liferay.social.kernel.service.persistence.SocialRequestUtil
070     * @generated
071     */
072    @ProviderType
073    public class SocialRequestPersistenceImpl extends BasePersistenceImpl<SocialRequest>
074            implements SocialRequestPersistence {
075            /*
076             * NOTE FOR DEVELOPERS:
077             *
078             * Never modify or reference this class directly. Always use {@link SocialRequestUtil} to access the social request persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
079             */
080            public static final String FINDER_CLASS_NAME_ENTITY = SocialRequestImpl.class.getName();
081            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List1";
083            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List2";
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
086                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
087                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
088                            "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
090                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
091                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
092                            "findAll", new String[0]);
093            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
094                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
097                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
098                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
099                            "findByUuid",
100                            new String[] {
101                                    String.class.getName(),
102                                    
103                            Integer.class.getName(), Integer.class.getName(),
104                                    OrderByComparator.class.getName()
105                            });
106            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
107                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
108                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
109                            "findByUuid", new String[] { String.class.getName() },
110                            SocialRequestModelImpl.UUID_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
112                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
114                            new String[] { String.class.getName() });
115    
116            /**
117             * Returns all the social requests where uuid = &#63;.
118             *
119             * @param uuid the uuid
120             * @return the matching social requests
121             */
122            @Override
123            public List<SocialRequest> findByUuid(String uuid) {
124                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125            }
126    
127            /**
128             * Returns a range of all the social requests where uuid = &#63;.
129             *
130             * <p>
131             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
132             * </p>
133             *
134             * @param uuid the uuid
135             * @param start the lower bound of the range of social requests
136             * @param end the upper bound of the range of social requests (not inclusive)
137             * @return the range of matching social requests
138             */
139            @Override
140            public List<SocialRequest> findByUuid(String uuid, int start, int end) {
141                    return findByUuid(uuid, start, end, null);
142            }
143    
144            /**
145             * Returns an ordered range of all the social requests where uuid = &#63;.
146             *
147             * <p>
148             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
149             * </p>
150             *
151             * @param uuid the uuid
152             * @param start the lower bound of the range of social requests
153             * @param end the upper bound of the range of social requests (not inclusive)
154             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
155             * @return the ordered range of matching social requests
156             */
157            @Override
158            public List<SocialRequest> findByUuid(String uuid, int start, int end,
159                    OrderByComparator<SocialRequest> orderByComparator) {
160                    return findByUuid(uuid, start, end, orderByComparator, true);
161            }
162    
163            /**
164             * Returns an ordered range of all the social requests where uuid = &#63;.
165             *
166             * <p>
167             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
168             * </p>
169             *
170             * @param uuid the uuid
171             * @param start the lower bound of the range of social requests
172             * @param end the upper bound of the range of social requests (not inclusive)
173             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
174             * @param retrieveFromCache whether to retrieve from the finder cache
175             * @return the ordered range of matching social requests
176             */
177            @Override
178            public List<SocialRequest> findByUuid(String uuid, int start, int end,
179                    OrderByComparator<SocialRequest> orderByComparator,
180                    boolean retrieveFromCache) {
181                    boolean pagination = true;
182                    FinderPath finderPath = null;
183                    Object[] finderArgs = null;
184    
185                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
186                                    (orderByComparator == null)) {
187                            pagination = false;
188                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
189                            finderArgs = new Object[] { uuid };
190                    }
191                    else {
192                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
193                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
194                    }
195    
196                    List<SocialRequest> list = null;
197    
198                    if (retrieveFromCache) {
199                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
200                                            finderArgs, this);
201    
202                            if ((list != null) && !list.isEmpty()) {
203                                    for (SocialRequest socialRequest : list) {
204                                            if (!Objects.equals(uuid, socialRequest.getUuid())) {
205                                                    list = null;
206    
207                                                    break;
208                                            }
209                                    }
210                            }
211                    }
212    
213                    if (list == null) {
214                            StringBundler query = null;
215    
216                            if (orderByComparator != null) {
217                                    query = new StringBundler(3 +
218                                                    (orderByComparator.getOrderByFields().length * 2));
219                            }
220                            else {
221                                    query = new StringBundler(3);
222                            }
223    
224                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
225    
226                            boolean bindUuid = false;
227    
228                            if (uuid == null) {
229                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
230                            }
231                            else if (uuid.equals(StringPool.BLANK)) {
232                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
233                            }
234                            else {
235                                    bindUuid = true;
236    
237                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
238                            }
239    
240                            if (orderByComparator != null) {
241                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
242                                            orderByComparator);
243                            }
244                            else
245                             if (pagination) {
246                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
247                            }
248    
249                            String sql = query.toString();
250    
251                            Session session = null;
252    
253                            try {
254                                    session = openSession();
255    
256                                    Query q = session.createQuery(sql);
257    
258                                    QueryPos qPos = QueryPos.getInstance(q);
259    
260                                    if (bindUuid) {
261                                            qPos.add(uuid);
262                                    }
263    
264                                    if (!pagination) {
265                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
266                                                            start, end, false);
267    
268                                            Collections.sort(list);
269    
270                                            list = Collections.unmodifiableList(list);
271                                    }
272                                    else {
273                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
274                                                            start, end);
275                                    }
276    
277                                    cacheResult(list);
278    
279                                    finderCache.putResult(finderPath, finderArgs, list);
280                            }
281                            catch (Exception e) {
282                                    finderCache.removeResult(finderPath, finderArgs);
283    
284                                    throw processException(e);
285                            }
286                            finally {
287                                    closeSession(session);
288                            }
289                    }
290    
291                    return list;
292            }
293    
294            /**
295             * Returns the first social request in the ordered set where uuid = &#63;.
296             *
297             * @param uuid the uuid
298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
299             * @return the first matching social request
300             * @throws NoSuchRequestException if a matching social request could not be found
301             */
302            @Override
303            public SocialRequest findByUuid_First(String uuid,
304                    OrderByComparator<SocialRequest> orderByComparator)
305                    throws NoSuchRequestException {
306                    SocialRequest socialRequest = fetchByUuid_First(uuid, orderByComparator);
307    
308                    if (socialRequest != null) {
309                            return socialRequest;
310                    }
311    
312                    StringBundler msg = new StringBundler(4);
313    
314                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
315    
316                    msg.append("uuid=");
317                    msg.append(uuid);
318    
319                    msg.append(StringPool.CLOSE_CURLY_BRACE);
320    
321                    throw new NoSuchRequestException(msg.toString());
322            }
323    
324            /**
325             * Returns the first social request in the ordered set where uuid = &#63;.
326             *
327             * @param uuid the uuid
328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
329             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
330             */
331            @Override
332            public SocialRequest fetchByUuid_First(String uuid,
333                    OrderByComparator<SocialRequest> orderByComparator) {
334                    List<SocialRequest> list = findByUuid(uuid, 0, 1, orderByComparator);
335    
336                    if (!list.isEmpty()) {
337                            return list.get(0);
338                    }
339    
340                    return null;
341            }
342    
343            /**
344             * Returns the last social request in the ordered set where uuid = &#63;.
345             *
346             * @param uuid the uuid
347             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
348             * @return the last matching social request
349             * @throws NoSuchRequestException if a matching social request could not be found
350             */
351            @Override
352            public SocialRequest findByUuid_Last(String uuid,
353                    OrderByComparator<SocialRequest> orderByComparator)
354                    throws NoSuchRequestException {
355                    SocialRequest socialRequest = fetchByUuid_Last(uuid, orderByComparator);
356    
357                    if (socialRequest != null) {
358                            return socialRequest;
359                    }
360    
361                    StringBundler msg = new StringBundler(4);
362    
363                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
364    
365                    msg.append("uuid=");
366                    msg.append(uuid);
367    
368                    msg.append(StringPool.CLOSE_CURLY_BRACE);
369    
370                    throw new NoSuchRequestException(msg.toString());
371            }
372    
373            /**
374             * Returns the last social request in the ordered set where uuid = &#63;.
375             *
376             * @param uuid the uuid
377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
378             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
379             */
380            @Override
381            public SocialRequest fetchByUuid_Last(String uuid,
382                    OrderByComparator<SocialRequest> orderByComparator) {
383                    int count = countByUuid(uuid);
384    
385                    if (count == 0) {
386                            return null;
387                    }
388    
389                    List<SocialRequest> list = findByUuid(uuid, count - 1, count,
390                                    orderByComparator);
391    
392                    if (!list.isEmpty()) {
393                            return list.get(0);
394                    }
395    
396                    return null;
397            }
398    
399            /**
400             * Returns the social requests before and after the current social request in the ordered set where uuid = &#63;.
401             *
402             * @param requestId the primary key of the current social request
403             * @param uuid the uuid
404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
405             * @return the previous, current, and next social request
406             * @throws NoSuchRequestException if a social request with the primary key could not be found
407             */
408            @Override
409            public SocialRequest[] findByUuid_PrevAndNext(long requestId, String uuid,
410                    OrderByComparator<SocialRequest> orderByComparator)
411                    throws NoSuchRequestException {
412                    SocialRequest socialRequest = findByPrimaryKey(requestId);
413    
414                    Session session = null;
415    
416                    try {
417                            session = openSession();
418    
419                            SocialRequest[] array = new SocialRequestImpl[3];
420    
421                            array[0] = getByUuid_PrevAndNext(session, socialRequest, uuid,
422                                            orderByComparator, true);
423    
424                            array[1] = socialRequest;
425    
426                            array[2] = getByUuid_PrevAndNext(session, socialRequest, uuid,
427                                            orderByComparator, false);
428    
429                            return array;
430                    }
431                    catch (Exception e) {
432                            throw processException(e);
433                    }
434                    finally {
435                            closeSession(session);
436                    }
437            }
438    
439            protected SocialRequest getByUuid_PrevAndNext(Session session,
440                    SocialRequest socialRequest, String uuid,
441                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
442                    StringBundler query = null;
443    
444                    if (orderByComparator != null) {
445                            query = new StringBundler(4 +
446                                            (orderByComparator.getOrderByConditionFields().length * 3) +
447                                            (orderByComparator.getOrderByFields().length * 3));
448                    }
449                    else {
450                            query = new StringBundler(3);
451                    }
452    
453                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
454    
455                    boolean bindUuid = false;
456    
457                    if (uuid == null) {
458                            query.append(_FINDER_COLUMN_UUID_UUID_1);
459                    }
460                    else if (uuid.equals(StringPool.BLANK)) {
461                            query.append(_FINDER_COLUMN_UUID_UUID_3);
462                    }
463                    else {
464                            bindUuid = true;
465    
466                            query.append(_FINDER_COLUMN_UUID_UUID_2);
467                    }
468    
469                    if (orderByComparator != null) {
470                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
471    
472                            if (orderByConditionFields.length > 0) {
473                                    query.append(WHERE_AND);
474                            }
475    
476                            for (int i = 0; i < orderByConditionFields.length; i++) {
477                                    query.append(_ORDER_BY_ENTITY_ALIAS);
478                                    query.append(orderByConditionFields[i]);
479    
480                                    if ((i + 1) < orderByConditionFields.length) {
481                                            if (orderByComparator.isAscending() ^ previous) {
482                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
483                                            }
484                                            else {
485                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
486                                            }
487                                    }
488                                    else {
489                                            if (orderByComparator.isAscending() ^ previous) {
490                                                    query.append(WHERE_GREATER_THAN);
491                                            }
492                                            else {
493                                                    query.append(WHERE_LESSER_THAN);
494                                            }
495                                    }
496                            }
497    
498                            query.append(ORDER_BY_CLAUSE);
499    
500                            String[] orderByFields = orderByComparator.getOrderByFields();
501    
502                            for (int i = 0; i < orderByFields.length; i++) {
503                                    query.append(_ORDER_BY_ENTITY_ALIAS);
504                                    query.append(orderByFields[i]);
505    
506                                    if ((i + 1) < orderByFields.length) {
507                                            if (orderByComparator.isAscending() ^ previous) {
508                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
509                                            }
510                                            else {
511                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
512                                            }
513                                    }
514                                    else {
515                                            if (orderByComparator.isAscending() ^ previous) {
516                                                    query.append(ORDER_BY_ASC);
517                                            }
518                                            else {
519                                                    query.append(ORDER_BY_DESC);
520                                            }
521                                    }
522                            }
523                    }
524                    else {
525                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
526                    }
527    
528                    String sql = query.toString();
529    
530                    Query q = session.createQuery(sql);
531    
532                    q.setFirstResult(0);
533                    q.setMaxResults(2);
534    
535                    QueryPos qPos = QueryPos.getInstance(q);
536    
537                    if (bindUuid) {
538                            qPos.add(uuid);
539                    }
540    
541                    if (orderByComparator != null) {
542                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
543    
544                            for (Object value : values) {
545                                    qPos.add(value);
546                            }
547                    }
548    
549                    List<SocialRequest> list = q.list();
550    
551                    if (list.size() == 2) {
552                            return list.get(1);
553                    }
554                    else {
555                            return null;
556                    }
557            }
558    
559            /**
560             * Removes all the social requests where uuid = &#63; from the database.
561             *
562             * @param uuid the uuid
563             */
564            @Override
565            public void removeByUuid(String uuid) {
566                    for (SocialRequest socialRequest : findByUuid(uuid, QueryUtil.ALL_POS,
567                                    QueryUtil.ALL_POS, null)) {
568                            remove(socialRequest);
569                    }
570            }
571    
572            /**
573             * Returns the number of social requests where uuid = &#63;.
574             *
575             * @param uuid the uuid
576             * @return the number of matching social requests
577             */
578            @Override
579            public int countByUuid(String uuid) {
580                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
581    
582                    Object[] finderArgs = new Object[] { uuid };
583    
584                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
585    
586                    if (count == null) {
587                            StringBundler query = new StringBundler(2);
588    
589                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
590    
591                            boolean bindUuid = false;
592    
593                            if (uuid == null) {
594                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
595                            }
596                            else if (uuid.equals(StringPool.BLANK)) {
597                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
598                            }
599                            else {
600                                    bindUuid = true;
601    
602                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
603                            }
604    
605                            String sql = query.toString();
606    
607                            Session session = null;
608    
609                            try {
610                                    session = openSession();
611    
612                                    Query q = session.createQuery(sql);
613    
614                                    QueryPos qPos = QueryPos.getInstance(q);
615    
616                                    if (bindUuid) {
617                                            qPos.add(uuid);
618                                    }
619    
620                                    count = (Long)q.uniqueResult();
621    
622                                    finderCache.putResult(finderPath, finderArgs, count);
623                            }
624                            catch (Exception e) {
625                                    finderCache.removeResult(finderPath, finderArgs);
626    
627                                    throw processException(e);
628                            }
629                            finally {
630                                    closeSession(session);
631                            }
632                    }
633    
634                    return count.intValue();
635            }
636    
637            private static final String _FINDER_COLUMN_UUID_UUID_1 = "socialRequest.uuid IS NULL";
638            private static final String _FINDER_COLUMN_UUID_UUID_2 = "socialRequest.uuid = ?";
639            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = '')";
640            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
641                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
642                            SocialRequestImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
643                            new String[] { String.class.getName(), Long.class.getName() },
644                            SocialRequestModelImpl.UUID_COLUMN_BITMASK |
645                            SocialRequestModelImpl.GROUPID_COLUMN_BITMASK);
646            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
647                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
648                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
649                            new String[] { String.class.getName(), Long.class.getName() });
650    
651            /**
652             * Returns the social request where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchRequestException} if it could not be found.
653             *
654             * @param uuid the uuid
655             * @param groupId the group ID
656             * @return the matching social request
657             * @throws NoSuchRequestException if a matching social request could not be found
658             */
659            @Override
660            public SocialRequest findByUUID_G(String uuid, long groupId)
661                    throws NoSuchRequestException {
662                    SocialRequest socialRequest = fetchByUUID_G(uuid, groupId);
663    
664                    if (socialRequest == null) {
665                            StringBundler msg = new StringBundler(6);
666    
667                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
668    
669                            msg.append("uuid=");
670                            msg.append(uuid);
671    
672                            msg.append(", groupId=");
673                            msg.append(groupId);
674    
675                            msg.append(StringPool.CLOSE_CURLY_BRACE);
676    
677                            if (_log.isDebugEnabled()) {
678                                    _log.debug(msg.toString());
679                            }
680    
681                            throw new NoSuchRequestException(msg.toString());
682                    }
683    
684                    return socialRequest;
685            }
686    
687            /**
688             * Returns the social request where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
689             *
690             * @param uuid the uuid
691             * @param groupId the group ID
692             * @return the matching social request, or <code>null</code> if a matching social request could not be found
693             */
694            @Override
695            public SocialRequest fetchByUUID_G(String uuid, long groupId) {
696                    return fetchByUUID_G(uuid, groupId, true);
697            }
698    
699            /**
700             * Returns the social request where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
701             *
702             * @param uuid the uuid
703             * @param groupId the group ID
704             * @param retrieveFromCache whether to retrieve from the finder cache
705             * @return the matching social request, or <code>null</code> if a matching social request could not be found
706             */
707            @Override
708            public SocialRequest fetchByUUID_G(String uuid, long groupId,
709                    boolean retrieveFromCache) {
710                    Object[] finderArgs = new Object[] { uuid, groupId };
711    
712                    Object result = null;
713    
714                    if (retrieveFromCache) {
715                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
716                                            finderArgs, this);
717                    }
718    
719                    if (result instanceof SocialRequest) {
720                            SocialRequest socialRequest = (SocialRequest)result;
721    
722                            if (!Objects.equals(uuid, socialRequest.getUuid()) ||
723                                            (groupId != socialRequest.getGroupId())) {
724                                    result = null;
725                            }
726                    }
727    
728                    if (result == null) {
729                            StringBundler query = new StringBundler(4);
730    
731                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
732    
733                            boolean bindUuid = false;
734    
735                            if (uuid == null) {
736                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
737                            }
738                            else if (uuid.equals(StringPool.BLANK)) {
739                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
740                            }
741                            else {
742                                    bindUuid = true;
743    
744                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
745                            }
746    
747                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
748    
749                            String sql = query.toString();
750    
751                            Session session = null;
752    
753                            try {
754                                    session = openSession();
755    
756                                    Query q = session.createQuery(sql);
757    
758                                    QueryPos qPos = QueryPos.getInstance(q);
759    
760                                    if (bindUuid) {
761                                            qPos.add(uuid);
762                                    }
763    
764                                    qPos.add(groupId);
765    
766                                    List<SocialRequest> list = q.list();
767    
768                                    if (list.isEmpty()) {
769                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
770                                                    finderArgs, list);
771                                    }
772                                    else {
773                                            SocialRequest socialRequest = list.get(0);
774    
775                                            result = socialRequest;
776    
777                                            cacheResult(socialRequest);
778    
779                                            if ((socialRequest.getUuid() == null) ||
780                                                            !socialRequest.getUuid().equals(uuid) ||
781                                                            (socialRequest.getGroupId() != groupId)) {
782                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
783                                                            finderArgs, socialRequest);
784                                            }
785                                    }
786                            }
787                            catch (Exception e) {
788                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
789    
790                                    throw processException(e);
791                            }
792                            finally {
793                                    closeSession(session);
794                            }
795                    }
796    
797                    if (result instanceof List<?>) {
798                            return null;
799                    }
800                    else {
801                            return (SocialRequest)result;
802                    }
803            }
804    
805            /**
806             * Removes the social request where uuid = &#63; and groupId = &#63; from the database.
807             *
808             * @param uuid the uuid
809             * @param groupId the group ID
810             * @return the social request that was removed
811             */
812            @Override
813            public SocialRequest removeByUUID_G(String uuid, long groupId)
814                    throws NoSuchRequestException {
815                    SocialRequest socialRequest = findByUUID_G(uuid, groupId);
816    
817                    return remove(socialRequest);
818            }
819    
820            /**
821             * Returns the number of social requests where uuid = &#63; and groupId = &#63;.
822             *
823             * @param uuid the uuid
824             * @param groupId the group ID
825             * @return the number of matching social requests
826             */
827            @Override
828            public int countByUUID_G(String uuid, long groupId) {
829                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
830    
831                    Object[] finderArgs = new Object[] { uuid, groupId };
832    
833                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
834    
835                    if (count == null) {
836                            StringBundler query = new StringBundler(3);
837    
838                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
839    
840                            boolean bindUuid = false;
841    
842                            if (uuid == null) {
843                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
844                            }
845                            else if (uuid.equals(StringPool.BLANK)) {
846                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
847                            }
848                            else {
849                                    bindUuid = true;
850    
851                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
852                            }
853    
854                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
855    
856                            String sql = query.toString();
857    
858                            Session session = null;
859    
860                            try {
861                                    session = openSession();
862    
863                                    Query q = session.createQuery(sql);
864    
865                                    QueryPos qPos = QueryPos.getInstance(q);
866    
867                                    if (bindUuid) {
868                                            qPos.add(uuid);
869                                    }
870    
871                                    qPos.add(groupId);
872    
873                                    count = (Long)q.uniqueResult();
874    
875                                    finderCache.putResult(finderPath, finderArgs, count);
876                            }
877                            catch (Exception e) {
878                                    finderCache.removeResult(finderPath, finderArgs);
879    
880                                    throw processException(e);
881                            }
882                            finally {
883                                    closeSession(session);
884                            }
885                    }
886    
887                    return count.intValue();
888            }
889    
890            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "socialRequest.uuid IS NULL AND ";
891            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "socialRequest.uuid = ? AND ";
892            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = '') AND ";
893            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "socialRequest.groupId = ?";
894            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
895                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
896                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
897                            "findByUuid_C",
898                            new String[] {
899                                    String.class.getName(), Long.class.getName(),
900                                    
901                            Integer.class.getName(), Integer.class.getName(),
902                                    OrderByComparator.class.getName()
903                            });
904            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
905                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
906                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
907                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
908                            "findByUuid_C",
909                            new String[] { String.class.getName(), Long.class.getName() },
910                            SocialRequestModelImpl.UUID_COLUMN_BITMASK |
911                            SocialRequestModelImpl.COMPANYID_COLUMN_BITMASK);
912            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
913                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
914                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
915                            new String[] { String.class.getName(), Long.class.getName() });
916    
917            /**
918             * Returns all the social requests where uuid = &#63; and companyId = &#63;.
919             *
920             * @param uuid the uuid
921             * @param companyId the company ID
922             * @return the matching social requests
923             */
924            @Override
925            public List<SocialRequest> findByUuid_C(String uuid, long companyId) {
926                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
927                            QueryUtil.ALL_POS, null);
928            }
929    
930            /**
931             * Returns a range of all the social requests where uuid = &#63; and companyId = &#63;.
932             *
933             * <p>
934             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
935             * </p>
936             *
937             * @param uuid the uuid
938             * @param companyId the company ID
939             * @param start the lower bound of the range of social requests
940             * @param end the upper bound of the range of social requests (not inclusive)
941             * @return the range of matching social requests
942             */
943            @Override
944            public List<SocialRequest> findByUuid_C(String uuid, long companyId,
945                    int start, int end) {
946                    return findByUuid_C(uuid, companyId, start, end, null);
947            }
948    
949            /**
950             * Returns an ordered range of all the social requests where uuid = &#63; and companyId = &#63;.
951             *
952             * <p>
953             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
954             * </p>
955             *
956             * @param uuid the uuid
957             * @param companyId the company ID
958             * @param start the lower bound of the range of social requests
959             * @param end the upper bound of the range of social requests (not inclusive)
960             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
961             * @return the ordered range of matching social requests
962             */
963            @Override
964            public List<SocialRequest> findByUuid_C(String uuid, long companyId,
965                    int start, int end, OrderByComparator<SocialRequest> orderByComparator) {
966                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
967            }
968    
969            /**
970             * Returns an ordered range of all the social requests where uuid = &#63; and companyId = &#63;.
971             *
972             * <p>
973             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
974             * </p>
975             *
976             * @param uuid the uuid
977             * @param companyId the company ID
978             * @param start the lower bound of the range of social requests
979             * @param end the upper bound of the range of social requests (not inclusive)
980             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
981             * @param retrieveFromCache whether to retrieve from the finder cache
982             * @return the ordered range of matching social requests
983             */
984            @Override
985            public List<SocialRequest> findByUuid_C(String uuid, long companyId,
986                    int start, int end, OrderByComparator<SocialRequest> orderByComparator,
987                    boolean retrieveFromCache) {
988                    boolean pagination = true;
989                    FinderPath finderPath = null;
990                    Object[] finderArgs = null;
991    
992                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
993                                    (orderByComparator == null)) {
994                            pagination = false;
995                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
996                            finderArgs = new Object[] { uuid, companyId };
997                    }
998                    else {
999                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1000                            finderArgs = new Object[] {
1001                                            uuid, companyId,
1002                                            
1003                                            start, end, orderByComparator
1004                                    };
1005                    }
1006    
1007                    List<SocialRequest> list = null;
1008    
1009                    if (retrieveFromCache) {
1010                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
1011                                            finderArgs, this);
1012    
1013                            if ((list != null) && !list.isEmpty()) {
1014                                    for (SocialRequest socialRequest : list) {
1015                                            if (!Objects.equals(uuid, socialRequest.getUuid()) ||
1016                                                            (companyId != socialRequest.getCompanyId())) {
1017                                                    list = null;
1018    
1019                                                    break;
1020                                            }
1021                                    }
1022                            }
1023                    }
1024    
1025                    if (list == null) {
1026                            StringBundler query = null;
1027    
1028                            if (orderByComparator != null) {
1029                                    query = new StringBundler(4 +
1030                                                    (orderByComparator.getOrderByFields().length * 2));
1031                            }
1032                            else {
1033                                    query = new StringBundler(4);
1034                            }
1035    
1036                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1037    
1038                            boolean bindUuid = false;
1039    
1040                            if (uuid == null) {
1041                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1042                            }
1043                            else if (uuid.equals(StringPool.BLANK)) {
1044                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1045                            }
1046                            else {
1047                                    bindUuid = true;
1048    
1049                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1050                            }
1051    
1052                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1053    
1054                            if (orderByComparator != null) {
1055                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1056                                            orderByComparator);
1057                            }
1058                            else
1059                             if (pagination) {
1060                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1061                            }
1062    
1063                            String sql = query.toString();
1064    
1065                            Session session = null;
1066    
1067                            try {
1068                                    session = openSession();
1069    
1070                                    Query q = session.createQuery(sql);
1071    
1072                                    QueryPos qPos = QueryPos.getInstance(q);
1073    
1074                                    if (bindUuid) {
1075                                            qPos.add(uuid);
1076                                    }
1077    
1078                                    qPos.add(companyId);
1079    
1080                                    if (!pagination) {
1081                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1082                                                            start, end, false);
1083    
1084                                            Collections.sort(list);
1085    
1086                                            list = Collections.unmodifiableList(list);
1087                                    }
1088                                    else {
1089                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1090                                                            start, end);
1091                                    }
1092    
1093                                    cacheResult(list);
1094    
1095                                    finderCache.putResult(finderPath, finderArgs, list);
1096                            }
1097                            catch (Exception e) {
1098                                    finderCache.removeResult(finderPath, finderArgs);
1099    
1100                                    throw processException(e);
1101                            }
1102                            finally {
1103                                    closeSession(session);
1104                            }
1105                    }
1106    
1107                    return list;
1108            }
1109    
1110            /**
1111             * Returns the first social request in the ordered set where uuid = &#63; and companyId = &#63;.
1112             *
1113             * @param uuid the uuid
1114             * @param companyId the company ID
1115             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1116             * @return the first matching social request
1117             * @throws NoSuchRequestException if a matching social request could not be found
1118             */
1119            @Override
1120            public SocialRequest findByUuid_C_First(String uuid, long companyId,
1121                    OrderByComparator<SocialRequest> orderByComparator)
1122                    throws NoSuchRequestException {
1123                    SocialRequest socialRequest = fetchByUuid_C_First(uuid, companyId,
1124                                    orderByComparator);
1125    
1126                    if (socialRequest != null) {
1127                            return socialRequest;
1128                    }
1129    
1130                    StringBundler msg = new StringBundler(6);
1131    
1132                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1133    
1134                    msg.append("uuid=");
1135                    msg.append(uuid);
1136    
1137                    msg.append(", companyId=");
1138                    msg.append(companyId);
1139    
1140                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1141    
1142                    throw new NoSuchRequestException(msg.toString());
1143            }
1144    
1145            /**
1146             * Returns the first social request in the ordered set where uuid = &#63; and companyId = &#63;.
1147             *
1148             * @param uuid the uuid
1149             * @param companyId the company ID
1150             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1151             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
1152             */
1153            @Override
1154            public SocialRequest fetchByUuid_C_First(String uuid, long companyId,
1155                    OrderByComparator<SocialRequest> orderByComparator) {
1156                    List<SocialRequest> list = findByUuid_C(uuid, companyId, 0, 1,
1157                                    orderByComparator);
1158    
1159                    if (!list.isEmpty()) {
1160                            return list.get(0);
1161                    }
1162    
1163                    return null;
1164            }
1165    
1166            /**
1167             * Returns the last social request in the ordered set where uuid = &#63; and companyId = &#63;.
1168             *
1169             * @param uuid the uuid
1170             * @param companyId the company ID
1171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1172             * @return the last matching social request
1173             * @throws NoSuchRequestException if a matching social request could not be found
1174             */
1175            @Override
1176            public SocialRequest findByUuid_C_Last(String uuid, long companyId,
1177                    OrderByComparator<SocialRequest> orderByComparator)
1178                    throws NoSuchRequestException {
1179                    SocialRequest socialRequest = fetchByUuid_C_Last(uuid, companyId,
1180                                    orderByComparator);
1181    
1182                    if (socialRequest != null) {
1183                            return socialRequest;
1184                    }
1185    
1186                    StringBundler msg = new StringBundler(6);
1187    
1188                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1189    
1190                    msg.append("uuid=");
1191                    msg.append(uuid);
1192    
1193                    msg.append(", companyId=");
1194                    msg.append(companyId);
1195    
1196                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1197    
1198                    throw new NoSuchRequestException(msg.toString());
1199            }
1200    
1201            /**
1202             * Returns the last social request in the ordered set where uuid = &#63; and companyId = &#63;.
1203             *
1204             * @param uuid the uuid
1205             * @param companyId the company ID
1206             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1207             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
1208             */
1209            @Override
1210            public SocialRequest fetchByUuid_C_Last(String uuid, long companyId,
1211                    OrderByComparator<SocialRequest> orderByComparator) {
1212                    int count = countByUuid_C(uuid, companyId);
1213    
1214                    if (count == 0) {
1215                            return null;
1216                    }
1217    
1218                    List<SocialRequest> list = findByUuid_C(uuid, companyId, count - 1,
1219                                    count, orderByComparator);
1220    
1221                    if (!list.isEmpty()) {
1222                            return list.get(0);
1223                    }
1224    
1225                    return null;
1226            }
1227    
1228            /**
1229             * Returns the social requests before and after the current social request in the ordered set where uuid = &#63; and companyId = &#63;.
1230             *
1231             * @param requestId the primary key of the current social request
1232             * @param uuid the uuid
1233             * @param companyId the company ID
1234             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1235             * @return the previous, current, and next social request
1236             * @throws NoSuchRequestException if a social request with the primary key could not be found
1237             */
1238            @Override
1239            public SocialRequest[] findByUuid_C_PrevAndNext(long requestId,
1240                    String uuid, long companyId,
1241                    OrderByComparator<SocialRequest> orderByComparator)
1242                    throws NoSuchRequestException {
1243                    SocialRequest socialRequest = findByPrimaryKey(requestId);
1244    
1245                    Session session = null;
1246    
1247                    try {
1248                            session = openSession();
1249    
1250                            SocialRequest[] array = new SocialRequestImpl[3];
1251    
1252                            array[0] = getByUuid_C_PrevAndNext(session, socialRequest, uuid,
1253                                            companyId, orderByComparator, true);
1254    
1255                            array[1] = socialRequest;
1256    
1257                            array[2] = getByUuid_C_PrevAndNext(session, socialRequest, uuid,
1258                                            companyId, orderByComparator, false);
1259    
1260                            return array;
1261                    }
1262                    catch (Exception e) {
1263                            throw processException(e);
1264                    }
1265                    finally {
1266                            closeSession(session);
1267                    }
1268            }
1269    
1270            protected SocialRequest getByUuid_C_PrevAndNext(Session session,
1271                    SocialRequest socialRequest, String uuid, long companyId,
1272                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
1273                    StringBundler query = null;
1274    
1275                    if (orderByComparator != null) {
1276                            query = new StringBundler(5 +
1277                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1278                                            (orderByComparator.getOrderByFields().length * 3));
1279                    }
1280                    else {
1281                            query = new StringBundler(4);
1282                    }
1283    
1284                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1285    
1286                    boolean bindUuid = false;
1287    
1288                    if (uuid == null) {
1289                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1290                    }
1291                    else if (uuid.equals(StringPool.BLANK)) {
1292                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1293                    }
1294                    else {
1295                            bindUuid = true;
1296    
1297                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1298                    }
1299    
1300                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1301    
1302                    if (orderByComparator != null) {
1303                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1304    
1305                            if (orderByConditionFields.length > 0) {
1306                                    query.append(WHERE_AND);
1307                            }
1308    
1309                            for (int i = 0; i < orderByConditionFields.length; i++) {
1310                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1311                                    query.append(orderByConditionFields[i]);
1312    
1313                                    if ((i + 1) < orderByConditionFields.length) {
1314                                            if (orderByComparator.isAscending() ^ previous) {
1315                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1316                                            }
1317                                            else {
1318                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1319                                            }
1320                                    }
1321                                    else {
1322                                            if (orderByComparator.isAscending() ^ previous) {
1323                                                    query.append(WHERE_GREATER_THAN);
1324                                            }
1325                                            else {
1326                                                    query.append(WHERE_LESSER_THAN);
1327                                            }
1328                                    }
1329                            }
1330    
1331                            query.append(ORDER_BY_CLAUSE);
1332    
1333                            String[] orderByFields = orderByComparator.getOrderByFields();
1334    
1335                            for (int i = 0; i < orderByFields.length; i++) {
1336                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1337                                    query.append(orderByFields[i]);
1338    
1339                                    if ((i + 1) < orderByFields.length) {
1340                                            if (orderByComparator.isAscending() ^ previous) {
1341                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1342                                            }
1343                                            else {
1344                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1345                                            }
1346                                    }
1347                                    else {
1348                                            if (orderByComparator.isAscending() ^ previous) {
1349                                                    query.append(ORDER_BY_ASC);
1350                                            }
1351                                            else {
1352                                                    query.append(ORDER_BY_DESC);
1353                                            }
1354                                    }
1355                            }
1356                    }
1357                    else {
1358                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1359                    }
1360    
1361                    String sql = query.toString();
1362    
1363                    Query q = session.createQuery(sql);
1364    
1365                    q.setFirstResult(0);
1366                    q.setMaxResults(2);
1367    
1368                    QueryPos qPos = QueryPos.getInstance(q);
1369    
1370                    if (bindUuid) {
1371                            qPos.add(uuid);
1372                    }
1373    
1374                    qPos.add(companyId);
1375    
1376                    if (orderByComparator != null) {
1377                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
1378    
1379                            for (Object value : values) {
1380                                    qPos.add(value);
1381                            }
1382                    }
1383    
1384                    List<SocialRequest> list = q.list();
1385    
1386                    if (list.size() == 2) {
1387                            return list.get(1);
1388                    }
1389                    else {
1390                            return null;
1391                    }
1392            }
1393    
1394            /**
1395             * Removes all the social requests where uuid = &#63; and companyId = &#63; from the database.
1396             *
1397             * @param uuid the uuid
1398             * @param companyId the company ID
1399             */
1400            @Override
1401            public void removeByUuid_C(String uuid, long companyId) {
1402                    for (SocialRequest socialRequest : findByUuid_C(uuid, companyId,
1403                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1404                            remove(socialRequest);
1405                    }
1406            }
1407    
1408            /**
1409             * Returns the number of social requests where uuid = &#63; and companyId = &#63;.
1410             *
1411             * @param uuid the uuid
1412             * @param companyId the company ID
1413             * @return the number of matching social requests
1414             */
1415            @Override
1416            public int countByUuid_C(String uuid, long companyId) {
1417                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1418    
1419                    Object[] finderArgs = new Object[] { uuid, companyId };
1420    
1421                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1422    
1423                    if (count == null) {
1424                            StringBundler query = new StringBundler(3);
1425    
1426                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
1427    
1428                            boolean bindUuid = false;
1429    
1430                            if (uuid == null) {
1431                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1432                            }
1433                            else if (uuid.equals(StringPool.BLANK)) {
1434                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1435                            }
1436                            else {
1437                                    bindUuid = true;
1438    
1439                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1440                            }
1441    
1442                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1443    
1444                            String sql = query.toString();
1445    
1446                            Session session = null;
1447    
1448                            try {
1449                                    session = openSession();
1450    
1451                                    Query q = session.createQuery(sql);
1452    
1453                                    QueryPos qPos = QueryPos.getInstance(q);
1454    
1455                                    if (bindUuid) {
1456                                            qPos.add(uuid);
1457                                    }
1458    
1459                                    qPos.add(companyId);
1460    
1461                                    count = (Long)q.uniqueResult();
1462    
1463                                    finderCache.putResult(finderPath, finderArgs, count);
1464                            }
1465                            catch (Exception e) {
1466                                    finderCache.removeResult(finderPath, finderArgs);
1467    
1468                                    throw processException(e);
1469                            }
1470                            finally {
1471                                    closeSession(session);
1472                            }
1473                    }
1474    
1475                    return count.intValue();
1476            }
1477    
1478            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "socialRequest.uuid IS NULL AND ";
1479            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "socialRequest.uuid = ? AND ";
1480            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(socialRequest.uuid IS NULL OR socialRequest.uuid = '') AND ";
1481            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "socialRequest.companyId = ?";
1482            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1483                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1484                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
1485                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1486                            "findByCompanyId",
1487                            new String[] {
1488                                    Long.class.getName(),
1489                                    
1490                            Integer.class.getName(), Integer.class.getName(),
1491                                    OrderByComparator.class.getName()
1492                            });
1493            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1494                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1495                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
1496                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1497                            "findByCompanyId", new String[] { Long.class.getName() },
1498                            SocialRequestModelImpl.COMPANYID_COLUMN_BITMASK);
1499            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1500                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
1501                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1502                            new String[] { Long.class.getName() });
1503    
1504            /**
1505             * Returns all the social requests where companyId = &#63;.
1506             *
1507             * @param companyId the company ID
1508             * @return the matching social requests
1509             */
1510            @Override
1511            public List<SocialRequest> findByCompanyId(long companyId) {
1512                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1513                            null);
1514            }
1515    
1516            /**
1517             * Returns a range of all the social requests where companyId = &#63;.
1518             *
1519             * <p>
1520             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1521             * </p>
1522             *
1523             * @param companyId the company ID
1524             * @param start the lower bound of the range of social requests
1525             * @param end the upper bound of the range of social requests (not inclusive)
1526             * @return the range of matching social requests
1527             */
1528            @Override
1529            public List<SocialRequest> findByCompanyId(long companyId, int start,
1530                    int end) {
1531                    return findByCompanyId(companyId, start, end, null);
1532            }
1533    
1534            /**
1535             * Returns an ordered range of all the social requests where companyId = &#63;.
1536             *
1537             * <p>
1538             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1539             * </p>
1540             *
1541             * @param companyId the company ID
1542             * @param start the lower bound of the range of social requests
1543             * @param end the upper bound of the range of social requests (not inclusive)
1544             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1545             * @return the ordered range of matching social requests
1546             */
1547            @Override
1548            public List<SocialRequest> findByCompanyId(long companyId, int start,
1549                    int end, OrderByComparator<SocialRequest> orderByComparator) {
1550                    return findByCompanyId(companyId, start, end, orderByComparator, true);
1551            }
1552    
1553            /**
1554             * Returns an ordered range of all the social requests where companyId = &#63;.
1555             *
1556             * <p>
1557             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1558             * </p>
1559             *
1560             * @param companyId the company ID
1561             * @param start the lower bound of the range of social requests
1562             * @param end the upper bound of the range of social requests (not inclusive)
1563             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1564             * @param retrieveFromCache whether to retrieve from the finder cache
1565             * @return the ordered range of matching social requests
1566             */
1567            @Override
1568            public List<SocialRequest> findByCompanyId(long companyId, int start,
1569                    int end, OrderByComparator<SocialRequest> orderByComparator,
1570                    boolean retrieveFromCache) {
1571                    boolean pagination = true;
1572                    FinderPath finderPath = null;
1573                    Object[] finderArgs = null;
1574    
1575                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1576                                    (orderByComparator == null)) {
1577                            pagination = false;
1578                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1579                            finderArgs = new Object[] { companyId };
1580                    }
1581                    else {
1582                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1583                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1584                    }
1585    
1586                    List<SocialRequest> list = null;
1587    
1588                    if (retrieveFromCache) {
1589                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
1590                                            finderArgs, this);
1591    
1592                            if ((list != null) && !list.isEmpty()) {
1593                                    for (SocialRequest socialRequest : list) {
1594                                            if ((companyId != socialRequest.getCompanyId())) {
1595                                                    list = null;
1596    
1597                                                    break;
1598                                            }
1599                                    }
1600                            }
1601                    }
1602    
1603                    if (list == null) {
1604                            StringBundler query = null;
1605    
1606                            if (orderByComparator != null) {
1607                                    query = new StringBundler(3 +
1608                                                    (orderByComparator.getOrderByFields().length * 2));
1609                            }
1610                            else {
1611                                    query = new StringBundler(3);
1612                            }
1613    
1614                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1615    
1616                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1617    
1618                            if (orderByComparator != null) {
1619                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1620                                            orderByComparator);
1621                            }
1622                            else
1623                             if (pagination) {
1624                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1625                            }
1626    
1627                            String sql = query.toString();
1628    
1629                            Session session = null;
1630    
1631                            try {
1632                                    session = openSession();
1633    
1634                                    Query q = session.createQuery(sql);
1635    
1636                                    QueryPos qPos = QueryPos.getInstance(q);
1637    
1638                                    qPos.add(companyId);
1639    
1640                                    if (!pagination) {
1641                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1642                                                            start, end, false);
1643    
1644                                            Collections.sort(list);
1645    
1646                                            list = Collections.unmodifiableList(list);
1647                                    }
1648                                    else {
1649                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
1650                                                            start, end);
1651                                    }
1652    
1653                                    cacheResult(list);
1654    
1655                                    finderCache.putResult(finderPath, finderArgs, list);
1656                            }
1657                            catch (Exception e) {
1658                                    finderCache.removeResult(finderPath, finderArgs);
1659    
1660                                    throw processException(e);
1661                            }
1662                            finally {
1663                                    closeSession(session);
1664                            }
1665                    }
1666    
1667                    return list;
1668            }
1669    
1670            /**
1671             * Returns the first social request in the ordered set where companyId = &#63;.
1672             *
1673             * @param companyId the company ID
1674             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1675             * @return the first matching social request
1676             * @throws NoSuchRequestException if a matching social request could not be found
1677             */
1678            @Override
1679            public SocialRequest findByCompanyId_First(long companyId,
1680                    OrderByComparator<SocialRequest> orderByComparator)
1681                    throws NoSuchRequestException {
1682                    SocialRequest socialRequest = fetchByCompanyId_First(companyId,
1683                                    orderByComparator);
1684    
1685                    if (socialRequest != null) {
1686                            return socialRequest;
1687                    }
1688    
1689                    StringBundler msg = new StringBundler(4);
1690    
1691                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1692    
1693                    msg.append("companyId=");
1694                    msg.append(companyId);
1695    
1696                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1697    
1698                    throw new NoSuchRequestException(msg.toString());
1699            }
1700    
1701            /**
1702             * Returns the first social request in the ordered set where companyId = &#63;.
1703             *
1704             * @param companyId the company ID
1705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1706             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
1707             */
1708            @Override
1709            public SocialRequest fetchByCompanyId_First(long companyId,
1710                    OrderByComparator<SocialRequest> orderByComparator) {
1711                    List<SocialRequest> list = findByCompanyId(companyId, 0, 1,
1712                                    orderByComparator);
1713    
1714                    if (!list.isEmpty()) {
1715                            return list.get(0);
1716                    }
1717    
1718                    return null;
1719            }
1720    
1721            /**
1722             * Returns the last social request in the ordered set where companyId = &#63;.
1723             *
1724             * @param companyId the company ID
1725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1726             * @return the last matching social request
1727             * @throws NoSuchRequestException if a matching social request could not be found
1728             */
1729            @Override
1730            public SocialRequest findByCompanyId_Last(long companyId,
1731                    OrderByComparator<SocialRequest> orderByComparator)
1732                    throws NoSuchRequestException {
1733                    SocialRequest socialRequest = fetchByCompanyId_Last(companyId,
1734                                    orderByComparator);
1735    
1736                    if (socialRequest != null) {
1737                            return socialRequest;
1738                    }
1739    
1740                    StringBundler msg = new StringBundler(4);
1741    
1742                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1743    
1744                    msg.append("companyId=");
1745                    msg.append(companyId);
1746    
1747                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1748    
1749                    throw new NoSuchRequestException(msg.toString());
1750            }
1751    
1752            /**
1753             * Returns the last social request in the ordered set where companyId = &#63;.
1754             *
1755             * @param companyId the company ID
1756             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1757             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
1758             */
1759            @Override
1760            public SocialRequest fetchByCompanyId_Last(long companyId,
1761                    OrderByComparator<SocialRequest> orderByComparator) {
1762                    int count = countByCompanyId(companyId);
1763    
1764                    if (count == 0) {
1765                            return null;
1766                    }
1767    
1768                    List<SocialRequest> list = findByCompanyId(companyId, count - 1, count,
1769                                    orderByComparator);
1770    
1771                    if (!list.isEmpty()) {
1772                            return list.get(0);
1773                    }
1774    
1775                    return null;
1776            }
1777    
1778            /**
1779             * Returns the social requests before and after the current social request in the ordered set where companyId = &#63;.
1780             *
1781             * @param requestId the primary key of the current social request
1782             * @param companyId the company ID
1783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1784             * @return the previous, current, and next social request
1785             * @throws NoSuchRequestException if a social request with the primary key could not be found
1786             */
1787            @Override
1788            public SocialRequest[] findByCompanyId_PrevAndNext(long requestId,
1789                    long companyId, OrderByComparator<SocialRequest> orderByComparator)
1790                    throws NoSuchRequestException {
1791                    SocialRequest socialRequest = findByPrimaryKey(requestId);
1792    
1793                    Session session = null;
1794    
1795                    try {
1796                            session = openSession();
1797    
1798                            SocialRequest[] array = new SocialRequestImpl[3];
1799    
1800                            array[0] = getByCompanyId_PrevAndNext(session, socialRequest,
1801                                            companyId, orderByComparator, true);
1802    
1803                            array[1] = socialRequest;
1804    
1805                            array[2] = getByCompanyId_PrevAndNext(session, socialRequest,
1806                                            companyId, orderByComparator, false);
1807    
1808                            return array;
1809                    }
1810                    catch (Exception e) {
1811                            throw processException(e);
1812                    }
1813                    finally {
1814                            closeSession(session);
1815                    }
1816            }
1817    
1818            protected SocialRequest getByCompanyId_PrevAndNext(Session session,
1819                    SocialRequest socialRequest, long companyId,
1820                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
1821                    StringBundler query = null;
1822    
1823                    if (orderByComparator != null) {
1824                            query = new StringBundler(4 +
1825                                            (orderByComparator.getOrderByConditionFields().length * 3) +
1826                                            (orderByComparator.getOrderByFields().length * 3));
1827                    }
1828                    else {
1829                            query = new StringBundler(3);
1830                    }
1831    
1832                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
1833    
1834                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1835    
1836                    if (orderByComparator != null) {
1837                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1838    
1839                            if (orderByConditionFields.length > 0) {
1840                                    query.append(WHERE_AND);
1841                            }
1842    
1843                            for (int i = 0; i < orderByConditionFields.length; i++) {
1844                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1845                                    query.append(orderByConditionFields[i]);
1846    
1847                                    if ((i + 1) < orderByConditionFields.length) {
1848                                            if (orderByComparator.isAscending() ^ previous) {
1849                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1850                                            }
1851                                            else {
1852                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1853                                            }
1854                                    }
1855                                    else {
1856                                            if (orderByComparator.isAscending() ^ previous) {
1857                                                    query.append(WHERE_GREATER_THAN);
1858                                            }
1859                                            else {
1860                                                    query.append(WHERE_LESSER_THAN);
1861                                            }
1862                                    }
1863                            }
1864    
1865                            query.append(ORDER_BY_CLAUSE);
1866    
1867                            String[] orderByFields = orderByComparator.getOrderByFields();
1868    
1869                            for (int i = 0; i < orderByFields.length; i++) {
1870                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1871                                    query.append(orderByFields[i]);
1872    
1873                                    if ((i + 1) < orderByFields.length) {
1874                                            if (orderByComparator.isAscending() ^ previous) {
1875                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1876                                            }
1877                                            else {
1878                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1879                                            }
1880                                    }
1881                                    else {
1882                                            if (orderByComparator.isAscending() ^ previous) {
1883                                                    query.append(ORDER_BY_ASC);
1884                                            }
1885                                            else {
1886                                                    query.append(ORDER_BY_DESC);
1887                                            }
1888                                    }
1889                            }
1890                    }
1891                    else {
1892                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
1893                    }
1894    
1895                    String sql = query.toString();
1896    
1897                    Query q = session.createQuery(sql);
1898    
1899                    q.setFirstResult(0);
1900                    q.setMaxResults(2);
1901    
1902                    QueryPos qPos = QueryPos.getInstance(q);
1903    
1904                    qPos.add(companyId);
1905    
1906                    if (orderByComparator != null) {
1907                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
1908    
1909                            for (Object value : values) {
1910                                    qPos.add(value);
1911                            }
1912                    }
1913    
1914                    List<SocialRequest> list = q.list();
1915    
1916                    if (list.size() == 2) {
1917                            return list.get(1);
1918                    }
1919                    else {
1920                            return null;
1921                    }
1922            }
1923    
1924            /**
1925             * Removes all the social requests where companyId = &#63; from the database.
1926             *
1927             * @param companyId the company ID
1928             */
1929            @Override
1930            public void removeByCompanyId(long companyId) {
1931                    for (SocialRequest socialRequest : findByCompanyId(companyId,
1932                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1933                            remove(socialRequest);
1934                    }
1935            }
1936    
1937            /**
1938             * Returns the number of social requests where companyId = &#63;.
1939             *
1940             * @param companyId the company ID
1941             * @return the number of matching social requests
1942             */
1943            @Override
1944            public int countByCompanyId(long companyId) {
1945                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1946    
1947                    Object[] finderArgs = new Object[] { companyId };
1948    
1949                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1950    
1951                    if (count == null) {
1952                            StringBundler query = new StringBundler(2);
1953    
1954                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
1955    
1956                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1957    
1958                            String sql = query.toString();
1959    
1960                            Session session = null;
1961    
1962                            try {
1963                                    session = openSession();
1964    
1965                                    Query q = session.createQuery(sql);
1966    
1967                                    QueryPos qPos = QueryPos.getInstance(q);
1968    
1969                                    qPos.add(companyId);
1970    
1971                                    count = (Long)q.uniqueResult();
1972    
1973                                    finderCache.putResult(finderPath, finderArgs, count);
1974                            }
1975                            catch (Exception e) {
1976                                    finderCache.removeResult(finderPath, finderArgs);
1977    
1978                                    throw processException(e);
1979                            }
1980                            finally {
1981                                    closeSession(session);
1982                            }
1983                    }
1984    
1985                    return count.intValue();
1986            }
1987    
1988            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "socialRequest.companyId = ?";
1989            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
1990                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
1991                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1992                            "findByUserId",
1993                            new String[] {
1994                                    Long.class.getName(),
1995                                    
1996                            Integer.class.getName(), Integer.class.getName(),
1997                                    OrderByComparator.class.getName()
1998                            });
1999            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
2000                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2001                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
2002                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2003                            "findByUserId", new String[] { Long.class.getName() },
2004                            SocialRequestModelImpl.USERID_COLUMN_BITMASK);
2005            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2006                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
2007                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
2008                            new String[] { Long.class.getName() });
2009    
2010            /**
2011             * Returns all the social requests where userId = &#63;.
2012             *
2013             * @param userId the user ID
2014             * @return the matching social requests
2015             */
2016            @Override
2017            public List<SocialRequest> findByUserId(long userId) {
2018                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2019            }
2020    
2021            /**
2022             * Returns a range of all the social requests where userId = &#63;.
2023             *
2024             * <p>
2025             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2026             * </p>
2027             *
2028             * @param userId the user ID
2029             * @param start the lower bound of the range of social requests
2030             * @param end the upper bound of the range of social requests (not inclusive)
2031             * @return the range of matching social requests
2032             */
2033            @Override
2034            public List<SocialRequest> findByUserId(long userId, int start, int end) {
2035                    return findByUserId(userId, start, end, null);
2036            }
2037    
2038            /**
2039             * Returns an ordered range of all the social requests where userId = &#63;.
2040             *
2041             * <p>
2042             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2043             * </p>
2044             *
2045             * @param userId the user ID
2046             * @param start the lower bound of the range of social requests
2047             * @param end the upper bound of the range of social requests (not inclusive)
2048             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2049             * @return the ordered range of matching social requests
2050             */
2051            @Override
2052            public List<SocialRequest> findByUserId(long userId, int start, int end,
2053                    OrderByComparator<SocialRequest> orderByComparator) {
2054                    return findByUserId(userId, start, end, orderByComparator, true);
2055            }
2056    
2057            /**
2058             * Returns an ordered range of all the social requests where userId = &#63;.
2059             *
2060             * <p>
2061             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2062             * </p>
2063             *
2064             * @param userId the user ID
2065             * @param start the lower bound of the range of social requests
2066             * @param end the upper bound of the range of social requests (not inclusive)
2067             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2068             * @param retrieveFromCache whether to retrieve from the finder cache
2069             * @return the ordered range of matching social requests
2070             */
2071            @Override
2072            public List<SocialRequest> findByUserId(long userId, int start, int end,
2073                    OrderByComparator<SocialRequest> orderByComparator,
2074                    boolean retrieveFromCache) {
2075                    boolean pagination = true;
2076                    FinderPath finderPath = null;
2077                    Object[] finderArgs = null;
2078    
2079                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2080                                    (orderByComparator == null)) {
2081                            pagination = false;
2082                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2083                            finderArgs = new Object[] { userId };
2084                    }
2085                    else {
2086                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2087                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2088                    }
2089    
2090                    List<SocialRequest> list = null;
2091    
2092                    if (retrieveFromCache) {
2093                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
2094                                            finderArgs, this);
2095    
2096                            if ((list != null) && !list.isEmpty()) {
2097                                    for (SocialRequest socialRequest : list) {
2098                                            if ((userId != socialRequest.getUserId())) {
2099                                                    list = null;
2100    
2101                                                    break;
2102                                            }
2103                                    }
2104                            }
2105                    }
2106    
2107                    if (list == null) {
2108                            StringBundler query = null;
2109    
2110                            if (orderByComparator != null) {
2111                                    query = new StringBundler(3 +
2112                                                    (orderByComparator.getOrderByFields().length * 2));
2113                            }
2114                            else {
2115                                    query = new StringBundler(3);
2116                            }
2117    
2118                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2119    
2120                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2121    
2122                            if (orderByComparator != null) {
2123                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2124                                            orderByComparator);
2125                            }
2126                            else
2127                             if (pagination) {
2128                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2129                            }
2130    
2131                            String sql = query.toString();
2132    
2133                            Session session = null;
2134    
2135                            try {
2136                                    session = openSession();
2137    
2138                                    Query q = session.createQuery(sql);
2139    
2140                                    QueryPos qPos = QueryPos.getInstance(q);
2141    
2142                                    qPos.add(userId);
2143    
2144                                    if (!pagination) {
2145                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2146                                                            start, end, false);
2147    
2148                                            Collections.sort(list);
2149    
2150                                            list = Collections.unmodifiableList(list);
2151                                    }
2152                                    else {
2153                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2154                                                            start, end);
2155                                    }
2156    
2157                                    cacheResult(list);
2158    
2159                                    finderCache.putResult(finderPath, finderArgs, list);
2160                            }
2161                            catch (Exception e) {
2162                                    finderCache.removeResult(finderPath, finderArgs);
2163    
2164                                    throw processException(e);
2165                            }
2166                            finally {
2167                                    closeSession(session);
2168                            }
2169                    }
2170    
2171                    return list;
2172            }
2173    
2174            /**
2175             * Returns the first social request in the ordered set where userId = &#63;.
2176             *
2177             * @param userId the user ID
2178             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2179             * @return the first matching social request
2180             * @throws NoSuchRequestException if a matching social request could not be found
2181             */
2182            @Override
2183            public SocialRequest findByUserId_First(long userId,
2184                    OrderByComparator<SocialRequest> orderByComparator)
2185                    throws NoSuchRequestException {
2186                    SocialRequest socialRequest = fetchByUserId_First(userId,
2187                                    orderByComparator);
2188    
2189                    if (socialRequest != null) {
2190                            return socialRequest;
2191                    }
2192    
2193                    StringBundler msg = new StringBundler(4);
2194    
2195                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2196    
2197                    msg.append("userId=");
2198                    msg.append(userId);
2199    
2200                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2201    
2202                    throw new NoSuchRequestException(msg.toString());
2203            }
2204    
2205            /**
2206             * Returns the first social request in the ordered set where userId = &#63;.
2207             *
2208             * @param userId the user ID
2209             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2210             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
2211             */
2212            @Override
2213            public SocialRequest fetchByUserId_First(long userId,
2214                    OrderByComparator<SocialRequest> orderByComparator) {
2215                    List<SocialRequest> list = findByUserId(userId, 0, 1, orderByComparator);
2216    
2217                    if (!list.isEmpty()) {
2218                            return list.get(0);
2219                    }
2220    
2221                    return null;
2222            }
2223    
2224            /**
2225             * Returns the last social request in the ordered set where userId = &#63;.
2226             *
2227             * @param userId the user ID
2228             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2229             * @return the last matching social request
2230             * @throws NoSuchRequestException if a matching social request could not be found
2231             */
2232            @Override
2233            public SocialRequest findByUserId_Last(long userId,
2234                    OrderByComparator<SocialRequest> orderByComparator)
2235                    throws NoSuchRequestException {
2236                    SocialRequest socialRequest = fetchByUserId_Last(userId,
2237                                    orderByComparator);
2238    
2239                    if (socialRequest != null) {
2240                            return socialRequest;
2241                    }
2242    
2243                    StringBundler msg = new StringBundler(4);
2244    
2245                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2246    
2247                    msg.append("userId=");
2248                    msg.append(userId);
2249    
2250                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2251    
2252                    throw new NoSuchRequestException(msg.toString());
2253            }
2254    
2255            /**
2256             * Returns the last social request in the ordered set where userId = &#63;.
2257             *
2258             * @param userId the user ID
2259             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2260             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
2261             */
2262            @Override
2263            public SocialRequest fetchByUserId_Last(long userId,
2264                    OrderByComparator<SocialRequest> orderByComparator) {
2265                    int count = countByUserId(userId);
2266    
2267                    if (count == 0) {
2268                            return null;
2269                    }
2270    
2271                    List<SocialRequest> list = findByUserId(userId, count - 1, count,
2272                                    orderByComparator);
2273    
2274                    if (!list.isEmpty()) {
2275                            return list.get(0);
2276                    }
2277    
2278                    return null;
2279            }
2280    
2281            /**
2282             * Returns the social requests before and after the current social request in the ordered set where userId = &#63;.
2283             *
2284             * @param requestId the primary key of the current social request
2285             * @param userId the user ID
2286             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2287             * @return the previous, current, and next social request
2288             * @throws NoSuchRequestException if a social request with the primary key could not be found
2289             */
2290            @Override
2291            public SocialRequest[] findByUserId_PrevAndNext(long requestId,
2292                    long userId, OrderByComparator<SocialRequest> orderByComparator)
2293                    throws NoSuchRequestException {
2294                    SocialRequest socialRequest = findByPrimaryKey(requestId);
2295    
2296                    Session session = null;
2297    
2298                    try {
2299                            session = openSession();
2300    
2301                            SocialRequest[] array = new SocialRequestImpl[3];
2302    
2303                            array[0] = getByUserId_PrevAndNext(session, socialRequest, userId,
2304                                            orderByComparator, true);
2305    
2306                            array[1] = socialRequest;
2307    
2308                            array[2] = getByUserId_PrevAndNext(session, socialRequest, userId,
2309                                            orderByComparator, false);
2310    
2311                            return array;
2312                    }
2313                    catch (Exception e) {
2314                            throw processException(e);
2315                    }
2316                    finally {
2317                            closeSession(session);
2318                    }
2319            }
2320    
2321            protected SocialRequest getByUserId_PrevAndNext(Session session,
2322                    SocialRequest socialRequest, long userId,
2323                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
2324                    StringBundler query = null;
2325    
2326                    if (orderByComparator != null) {
2327                            query = new StringBundler(4 +
2328                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2329                                            (orderByComparator.getOrderByFields().length * 3));
2330                    }
2331                    else {
2332                            query = new StringBundler(3);
2333                    }
2334    
2335                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2336    
2337                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2338    
2339                    if (orderByComparator != null) {
2340                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2341    
2342                            if (orderByConditionFields.length > 0) {
2343                                    query.append(WHERE_AND);
2344                            }
2345    
2346                            for (int i = 0; i < orderByConditionFields.length; i++) {
2347                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2348                                    query.append(orderByConditionFields[i]);
2349    
2350                                    if ((i + 1) < orderByConditionFields.length) {
2351                                            if (orderByComparator.isAscending() ^ previous) {
2352                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2353                                            }
2354                                            else {
2355                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2356                                            }
2357                                    }
2358                                    else {
2359                                            if (orderByComparator.isAscending() ^ previous) {
2360                                                    query.append(WHERE_GREATER_THAN);
2361                                            }
2362                                            else {
2363                                                    query.append(WHERE_LESSER_THAN);
2364                                            }
2365                                    }
2366                            }
2367    
2368                            query.append(ORDER_BY_CLAUSE);
2369    
2370                            String[] orderByFields = orderByComparator.getOrderByFields();
2371    
2372                            for (int i = 0; i < orderByFields.length; i++) {
2373                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2374                                    query.append(orderByFields[i]);
2375    
2376                                    if ((i + 1) < orderByFields.length) {
2377                                            if (orderByComparator.isAscending() ^ previous) {
2378                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2379                                            }
2380                                            else {
2381                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2382                                            }
2383                                    }
2384                                    else {
2385                                            if (orderByComparator.isAscending() ^ previous) {
2386                                                    query.append(ORDER_BY_ASC);
2387                                            }
2388                                            else {
2389                                                    query.append(ORDER_BY_DESC);
2390                                            }
2391                                    }
2392                            }
2393                    }
2394                    else {
2395                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2396                    }
2397    
2398                    String sql = query.toString();
2399    
2400                    Query q = session.createQuery(sql);
2401    
2402                    q.setFirstResult(0);
2403                    q.setMaxResults(2);
2404    
2405                    QueryPos qPos = QueryPos.getInstance(q);
2406    
2407                    qPos.add(userId);
2408    
2409                    if (orderByComparator != null) {
2410                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
2411    
2412                            for (Object value : values) {
2413                                    qPos.add(value);
2414                            }
2415                    }
2416    
2417                    List<SocialRequest> list = q.list();
2418    
2419                    if (list.size() == 2) {
2420                            return list.get(1);
2421                    }
2422                    else {
2423                            return null;
2424                    }
2425            }
2426    
2427            /**
2428             * Removes all the social requests where userId = &#63; from the database.
2429             *
2430             * @param userId the user ID
2431             */
2432            @Override
2433            public void removeByUserId(long userId) {
2434                    for (SocialRequest socialRequest : findByUserId(userId,
2435                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2436                            remove(socialRequest);
2437                    }
2438            }
2439    
2440            /**
2441             * Returns the number of social requests where userId = &#63;.
2442             *
2443             * @param userId the user ID
2444             * @return the number of matching social requests
2445             */
2446            @Override
2447            public int countByUserId(long userId) {
2448                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
2449    
2450                    Object[] finderArgs = new Object[] { userId };
2451    
2452                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2453    
2454                    if (count == null) {
2455                            StringBundler query = new StringBundler(2);
2456    
2457                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
2458    
2459                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2460    
2461                            String sql = query.toString();
2462    
2463                            Session session = null;
2464    
2465                            try {
2466                                    session = openSession();
2467    
2468                                    Query q = session.createQuery(sql);
2469    
2470                                    QueryPos qPos = QueryPos.getInstance(q);
2471    
2472                                    qPos.add(userId);
2473    
2474                                    count = (Long)q.uniqueResult();
2475    
2476                                    finderCache.putResult(finderPath, finderArgs, count);
2477                            }
2478                            catch (Exception e) {
2479                                    finderCache.removeResult(finderPath, finderArgs);
2480    
2481                                    throw processException(e);
2482                            }
2483                            finally {
2484                                    closeSession(session);
2485                            }
2486                    }
2487    
2488                    return count.intValue();
2489            }
2490    
2491            private static final String _FINDER_COLUMN_USERID_USERID_2 = "socialRequest.userId = ?";
2492            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID =
2493                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2494                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
2495                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2496                            "findByReceiverUserId",
2497                            new String[] {
2498                                    Long.class.getName(),
2499                                    
2500                            Integer.class.getName(), Integer.class.getName(),
2501                                    OrderByComparator.class.getName()
2502                            });
2503            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID =
2504                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2505                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
2506                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2507                            "findByReceiverUserId", new String[] { Long.class.getName() },
2508                            SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
2509            public static final FinderPath FINDER_PATH_COUNT_BY_RECEIVERUSERID = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
2510                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
2511                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByReceiverUserId",
2512                            new String[] { Long.class.getName() });
2513    
2514            /**
2515             * Returns all the social requests where receiverUserId = &#63;.
2516             *
2517             * @param receiverUserId the receiver user ID
2518             * @return the matching social requests
2519             */
2520            @Override
2521            public List<SocialRequest> findByReceiverUserId(long receiverUserId) {
2522                    return findByReceiverUserId(receiverUserId, QueryUtil.ALL_POS,
2523                            QueryUtil.ALL_POS, null);
2524            }
2525    
2526            /**
2527             * Returns a range of all the social requests where receiverUserId = &#63;.
2528             *
2529             * <p>
2530             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2531             * </p>
2532             *
2533             * @param receiverUserId the receiver user ID
2534             * @param start the lower bound of the range of social requests
2535             * @param end the upper bound of the range of social requests (not inclusive)
2536             * @return the range of matching social requests
2537             */
2538            @Override
2539            public List<SocialRequest> findByReceiverUserId(long receiverUserId,
2540                    int start, int end) {
2541                    return findByReceiverUserId(receiverUserId, start, end, null);
2542            }
2543    
2544            /**
2545             * Returns an ordered range of all the social requests where receiverUserId = &#63;.
2546             *
2547             * <p>
2548             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2549             * </p>
2550             *
2551             * @param receiverUserId the receiver user ID
2552             * @param start the lower bound of the range of social requests
2553             * @param end the upper bound of the range of social requests (not inclusive)
2554             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2555             * @return the ordered range of matching social requests
2556             */
2557            @Override
2558            public List<SocialRequest> findByReceiverUserId(long receiverUserId,
2559                    int start, int end, OrderByComparator<SocialRequest> orderByComparator) {
2560                    return findByReceiverUserId(receiverUserId, start, end,
2561                            orderByComparator, true);
2562            }
2563    
2564            /**
2565             * Returns an ordered range of all the social requests where receiverUserId = &#63;.
2566             *
2567             * <p>
2568             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2569             * </p>
2570             *
2571             * @param receiverUserId the receiver user ID
2572             * @param start the lower bound of the range of social requests
2573             * @param end the upper bound of the range of social requests (not inclusive)
2574             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2575             * @param retrieveFromCache whether to retrieve from the finder cache
2576             * @return the ordered range of matching social requests
2577             */
2578            @Override
2579            public List<SocialRequest> findByReceiverUserId(long receiverUserId,
2580                    int start, int end, OrderByComparator<SocialRequest> orderByComparator,
2581                    boolean retrieveFromCache) {
2582                    boolean pagination = true;
2583                    FinderPath finderPath = null;
2584                    Object[] finderArgs = null;
2585    
2586                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2587                                    (orderByComparator == null)) {
2588                            pagination = false;
2589                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID;
2590                            finderArgs = new Object[] { receiverUserId };
2591                    }
2592                    else {
2593                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RECEIVERUSERID;
2594                            finderArgs = new Object[] {
2595                                            receiverUserId,
2596                                            
2597                                            start, end, orderByComparator
2598                                    };
2599                    }
2600    
2601                    List<SocialRequest> list = null;
2602    
2603                    if (retrieveFromCache) {
2604                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
2605                                            finderArgs, this);
2606    
2607                            if ((list != null) && !list.isEmpty()) {
2608                                    for (SocialRequest socialRequest : list) {
2609                                            if ((receiverUserId != socialRequest.getReceiverUserId())) {
2610                                                    list = null;
2611    
2612                                                    break;
2613                                            }
2614                                    }
2615                            }
2616                    }
2617    
2618                    if (list == null) {
2619                            StringBundler query = null;
2620    
2621                            if (orderByComparator != null) {
2622                                    query = new StringBundler(3 +
2623                                                    (orderByComparator.getOrderByFields().length * 2));
2624                            }
2625                            else {
2626                                    query = new StringBundler(3);
2627                            }
2628    
2629                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2630    
2631                            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2632    
2633                            if (orderByComparator != null) {
2634                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2635                                            orderByComparator);
2636                            }
2637                            else
2638                             if (pagination) {
2639                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2640                            }
2641    
2642                            String sql = query.toString();
2643    
2644                            Session session = null;
2645    
2646                            try {
2647                                    session = openSession();
2648    
2649                                    Query q = session.createQuery(sql);
2650    
2651                                    QueryPos qPos = QueryPos.getInstance(q);
2652    
2653                                    qPos.add(receiverUserId);
2654    
2655                                    if (!pagination) {
2656                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2657                                                            start, end, false);
2658    
2659                                            Collections.sort(list);
2660    
2661                                            list = Collections.unmodifiableList(list);
2662                                    }
2663                                    else {
2664                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
2665                                                            start, end);
2666                                    }
2667    
2668                                    cacheResult(list);
2669    
2670                                    finderCache.putResult(finderPath, finderArgs, list);
2671                            }
2672                            catch (Exception e) {
2673                                    finderCache.removeResult(finderPath, finderArgs);
2674    
2675                                    throw processException(e);
2676                            }
2677                            finally {
2678                                    closeSession(session);
2679                            }
2680                    }
2681    
2682                    return list;
2683            }
2684    
2685            /**
2686             * Returns the first social request in the ordered set where receiverUserId = &#63;.
2687             *
2688             * @param receiverUserId the receiver user ID
2689             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2690             * @return the first matching social request
2691             * @throws NoSuchRequestException if a matching social request could not be found
2692             */
2693            @Override
2694            public SocialRequest findByReceiverUserId_First(long receiverUserId,
2695                    OrderByComparator<SocialRequest> orderByComparator)
2696                    throws NoSuchRequestException {
2697                    SocialRequest socialRequest = fetchByReceiverUserId_First(receiverUserId,
2698                                    orderByComparator);
2699    
2700                    if (socialRequest != null) {
2701                            return socialRequest;
2702                    }
2703    
2704                    StringBundler msg = new StringBundler(4);
2705    
2706                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2707    
2708                    msg.append("receiverUserId=");
2709                    msg.append(receiverUserId);
2710    
2711                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2712    
2713                    throw new NoSuchRequestException(msg.toString());
2714            }
2715    
2716            /**
2717             * Returns the first social request in the ordered set where receiverUserId = &#63;.
2718             *
2719             * @param receiverUserId the receiver user ID
2720             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2721             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
2722             */
2723            @Override
2724            public SocialRequest fetchByReceiverUserId_First(long receiverUserId,
2725                    OrderByComparator<SocialRequest> orderByComparator) {
2726                    List<SocialRequest> list = findByReceiverUserId(receiverUserId, 0, 1,
2727                                    orderByComparator);
2728    
2729                    if (!list.isEmpty()) {
2730                            return list.get(0);
2731                    }
2732    
2733                    return null;
2734            }
2735    
2736            /**
2737             * Returns the last social request in the ordered set where receiverUserId = &#63;.
2738             *
2739             * @param receiverUserId the receiver user ID
2740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2741             * @return the last matching social request
2742             * @throws NoSuchRequestException if a matching social request could not be found
2743             */
2744            @Override
2745            public SocialRequest findByReceiverUserId_Last(long receiverUserId,
2746                    OrderByComparator<SocialRequest> orderByComparator)
2747                    throws NoSuchRequestException {
2748                    SocialRequest socialRequest = fetchByReceiverUserId_Last(receiverUserId,
2749                                    orderByComparator);
2750    
2751                    if (socialRequest != null) {
2752                            return socialRequest;
2753                    }
2754    
2755                    StringBundler msg = new StringBundler(4);
2756    
2757                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2758    
2759                    msg.append("receiverUserId=");
2760                    msg.append(receiverUserId);
2761    
2762                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2763    
2764                    throw new NoSuchRequestException(msg.toString());
2765            }
2766    
2767            /**
2768             * Returns the last social request in the ordered set where receiverUserId = &#63;.
2769             *
2770             * @param receiverUserId the receiver user ID
2771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2772             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
2773             */
2774            @Override
2775            public SocialRequest fetchByReceiverUserId_Last(long receiverUserId,
2776                    OrderByComparator<SocialRequest> orderByComparator) {
2777                    int count = countByReceiverUserId(receiverUserId);
2778    
2779                    if (count == 0) {
2780                            return null;
2781                    }
2782    
2783                    List<SocialRequest> list = findByReceiverUserId(receiverUserId,
2784                                    count - 1, count, orderByComparator);
2785    
2786                    if (!list.isEmpty()) {
2787                            return list.get(0);
2788                    }
2789    
2790                    return null;
2791            }
2792    
2793            /**
2794             * Returns the social requests before and after the current social request in the ordered set where receiverUserId = &#63;.
2795             *
2796             * @param requestId the primary key of the current social request
2797             * @param receiverUserId the receiver user ID
2798             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2799             * @return the previous, current, and next social request
2800             * @throws NoSuchRequestException if a social request with the primary key could not be found
2801             */
2802            @Override
2803            public SocialRequest[] findByReceiverUserId_PrevAndNext(long requestId,
2804                    long receiverUserId, OrderByComparator<SocialRequest> orderByComparator)
2805                    throws NoSuchRequestException {
2806                    SocialRequest socialRequest = findByPrimaryKey(requestId);
2807    
2808                    Session session = null;
2809    
2810                    try {
2811                            session = openSession();
2812    
2813                            SocialRequest[] array = new SocialRequestImpl[3];
2814    
2815                            array[0] = getByReceiverUserId_PrevAndNext(session, socialRequest,
2816                                            receiverUserId, orderByComparator, true);
2817    
2818                            array[1] = socialRequest;
2819    
2820                            array[2] = getByReceiverUserId_PrevAndNext(session, socialRequest,
2821                                            receiverUserId, orderByComparator, false);
2822    
2823                            return array;
2824                    }
2825                    catch (Exception e) {
2826                            throw processException(e);
2827                    }
2828                    finally {
2829                            closeSession(session);
2830                    }
2831            }
2832    
2833            protected SocialRequest getByReceiverUserId_PrevAndNext(Session session,
2834                    SocialRequest socialRequest, long receiverUserId,
2835                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
2836                    StringBundler query = null;
2837    
2838                    if (orderByComparator != null) {
2839                            query = new StringBundler(4 +
2840                                            (orderByComparator.getOrderByConditionFields().length * 3) +
2841                                            (orderByComparator.getOrderByFields().length * 3));
2842                    }
2843                    else {
2844                            query = new StringBundler(3);
2845                    }
2846    
2847                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
2848    
2849                    query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2850    
2851                    if (orderByComparator != null) {
2852                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2853    
2854                            if (orderByConditionFields.length > 0) {
2855                                    query.append(WHERE_AND);
2856                            }
2857    
2858                            for (int i = 0; i < orderByConditionFields.length; i++) {
2859                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2860                                    query.append(orderByConditionFields[i]);
2861    
2862                                    if ((i + 1) < orderByConditionFields.length) {
2863                                            if (orderByComparator.isAscending() ^ previous) {
2864                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2865                                            }
2866                                            else {
2867                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2868                                            }
2869                                    }
2870                                    else {
2871                                            if (orderByComparator.isAscending() ^ previous) {
2872                                                    query.append(WHERE_GREATER_THAN);
2873                                            }
2874                                            else {
2875                                                    query.append(WHERE_LESSER_THAN);
2876                                            }
2877                                    }
2878                            }
2879    
2880                            query.append(ORDER_BY_CLAUSE);
2881    
2882                            String[] orderByFields = orderByComparator.getOrderByFields();
2883    
2884                            for (int i = 0; i < orderByFields.length; i++) {
2885                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2886                                    query.append(orderByFields[i]);
2887    
2888                                    if ((i + 1) < orderByFields.length) {
2889                                            if (orderByComparator.isAscending() ^ previous) {
2890                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2891                                            }
2892                                            else {
2893                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2894                                            }
2895                                    }
2896                                    else {
2897                                            if (orderByComparator.isAscending() ^ previous) {
2898                                                    query.append(ORDER_BY_ASC);
2899                                            }
2900                                            else {
2901                                                    query.append(ORDER_BY_DESC);
2902                                            }
2903                                    }
2904                            }
2905                    }
2906                    else {
2907                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
2908                    }
2909    
2910                    String sql = query.toString();
2911    
2912                    Query q = session.createQuery(sql);
2913    
2914                    q.setFirstResult(0);
2915                    q.setMaxResults(2);
2916    
2917                    QueryPos qPos = QueryPos.getInstance(q);
2918    
2919                    qPos.add(receiverUserId);
2920    
2921                    if (orderByComparator != null) {
2922                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
2923    
2924                            for (Object value : values) {
2925                                    qPos.add(value);
2926                            }
2927                    }
2928    
2929                    List<SocialRequest> list = q.list();
2930    
2931                    if (list.size() == 2) {
2932                            return list.get(1);
2933                    }
2934                    else {
2935                            return null;
2936                    }
2937            }
2938    
2939            /**
2940             * Removes all the social requests where receiverUserId = &#63; from the database.
2941             *
2942             * @param receiverUserId the receiver user ID
2943             */
2944            @Override
2945            public void removeByReceiverUserId(long receiverUserId) {
2946                    for (SocialRequest socialRequest : findByReceiverUserId(
2947                                    receiverUserId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2948                            remove(socialRequest);
2949                    }
2950            }
2951    
2952            /**
2953             * Returns the number of social requests where receiverUserId = &#63;.
2954             *
2955             * @param receiverUserId the receiver user ID
2956             * @return the number of matching social requests
2957             */
2958            @Override
2959            public int countByReceiverUserId(long receiverUserId) {
2960                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RECEIVERUSERID;
2961    
2962                    Object[] finderArgs = new Object[] { receiverUserId };
2963    
2964                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2965    
2966                    if (count == null) {
2967                            StringBundler query = new StringBundler(2);
2968    
2969                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
2970    
2971                            query.append(_FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2);
2972    
2973                            String sql = query.toString();
2974    
2975                            Session session = null;
2976    
2977                            try {
2978                                    session = openSession();
2979    
2980                                    Query q = session.createQuery(sql);
2981    
2982                                    QueryPos qPos = QueryPos.getInstance(q);
2983    
2984                                    qPos.add(receiverUserId);
2985    
2986                                    count = (Long)q.uniqueResult();
2987    
2988                                    finderCache.putResult(finderPath, finderArgs, count);
2989                            }
2990                            catch (Exception e) {
2991                                    finderCache.removeResult(finderPath, finderArgs);
2992    
2993                                    throw processException(e);
2994                            }
2995                            finally {
2996                                    closeSession(session);
2997                            }
2998                    }
2999    
3000                    return count.intValue();
3001            }
3002    
3003            private static final String _FINDER_COLUMN_RECEIVERUSERID_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ?";
3004            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3005                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
3006                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3007                            "findByU_S",
3008                            new String[] {
3009                                    Long.class.getName(), Integer.class.getName(),
3010                                    
3011                            Integer.class.getName(), Integer.class.getName(),
3012                                    OrderByComparator.class.getName()
3013                            });
3014            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3015                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
3016                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3017                            "findByU_S",
3018                            new String[] { Long.class.getName(), Integer.class.getName() },
3019                            SocialRequestModelImpl.USERID_COLUMN_BITMASK |
3020                            SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
3021            public static final FinderPath FINDER_PATH_COUNT_BY_U_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3022                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
3023                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_S",
3024                            new String[] { Long.class.getName(), Integer.class.getName() });
3025    
3026            /**
3027             * Returns all the social requests where userId = &#63; and status = &#63;.
3028             *
3029             * @param userId the user ID
3030             * @param status the status
3031             * @return the matching social requests
3032             */
3033            @Override
3034            public List<SocialRequest> findByU_S(long userId, int status) {
3035                    return findByU_S(userId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3036                            null);
3037            }
3038    
3039            /**
3040             * Returns a range of all the social requests where userId = &#63; and status = &#63;.
3041             *
3042             * <p>
3043             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3044             * </p>
3045             *
3046             * @param userId the user ID
3047             * @param status the status
3048             * @param start the lower bound of the range of social requests
3049             * @param end the upper bound of the range of social requests (not inclusive)
3050             * @return the range of matching social requests
3051             */
3052            @Override
3053            public List<SocialRequest> findByU_S(long userId, int status, int start,
3054                    int end) {
3055                    return findByU_S(userId, status, start, end, null);
3056            }
3057    
3058            /**
3059             * Returns an ordered range of all the social requests where userId = &#63; and status = &#63;.
3060             *
3061             * <p>
3062             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3063             * </p>
3064             *
3065             * @param userId the user ID
3066             * @param status the status
3067             * @param start the lower bound of the range of social requests
3068             * @param end the upper bound of the range of social requests (not inclusive)
3069             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3070             * @return the ordered range of matching social requests
3071             */
3072            @Override
3073            public List<SocialRequest> findByU_S(long userId, int status, int start,
3074                    int end, OrderByComparator<SocialRequest> orderByComparator) {
3075                    return findByU_S(userId, status, start, end, orderByComparator, true);
3076            }
3077    
3078            /**
3079             * Returns an ordered range of all the social requests where userId = &#63; and status = &#63;.
3080             *
3081             * <p>
3082             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3083             * </p>
3084             *
3085             * @param userId the user ID
3086             * @param status the status
3087             * @param start the lower bound of the range of social requests
3088             * @param end the upper bound of the range of social requests (not inclusive)
3089             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3090             * @param retrieveFromCache whether to retrieve from the finder cache
3091             * @return the ordered range of matching social requests
3092             */
3093            @Override
3094            public List<SocialRequest> findByU_S(long userId, int status, int start,
3095                    int end, OrderByComparator<SocialRequest> orderByComparator,
3096                    boolean retrieveFromCache) {
3097                    boolean pagination = true;
3098                    FinderPath finderPath = null;
3099                    Object[] finderArgs = null;
3100    
3101                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3102                                    (orderByComparator == null)) {
3103                            pagination = false;
3104                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S;
3105                            finderArgs = new Object[] { userId, status };
3106                    }
3107                    else {
3108                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_S;
3109                            finderArgs = new Object[] {
3110                                            userId, status,
3111                                            
3112                                            start, end, orderByComparator
3113                                    };
3114                    }
3115    
3116                    List<SocialRequest> list = null;
3117    
3118                    if (retrieveFromCache) {
3119                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
3120                                            finderArgs, this);
3121    
3122                            if ((list != null) && !list.isEmpty()) {
3123                                    for (SocialRequest socialRequest : list) {
3124                                            if ((userId != socialRequest.getUserId()) ||
3125                                                            (status != socialRequest.getStatus())) {
3126                                                    list = null;
3127    
3128                                                    break;
3129                                            }
3130                                    }
3131                            }
3132                    }
3133    
3134                    if (list == null) {
3135                            StringBundler query = null;
3136    
3137                            if (orderByComparator != null) {
3138                                    query = new StringBundler(4 +
3139                                                    (orderByComparator.getOrderByFields().length * 2));
3140                            }
3141                            else {
3142                                    query = new StringBundler(4);
3143                            }
3144    
3145                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3146    
3147                            query.append(_FINDER_COLUMN_U_S_USERID_2);
3148    
3149                            query.append(_FINDER_COLUMN_U_S_STATUS_2);
3150    
3151                            if (orderByComparator != null) {
3152                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3153                                            orderByComparator);
3154                            }
3155                            else
3156                             if (pagination) {
3157                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3158                            }
3159    
3160                            String sql = query.toString();
3161    
3162                            Session session = null;
3163    
3164                            try {
3165                                    session = openSession();
3166    
3167                                    Query q = session.createQuery(sql);
3168    
3169                                    QueryPos qPos = QueryPos.getInstance(q);
3170    
3171                                    qPos.add(userId);
3172    
3173                                    qPos.add(status);
3174    
3175                                    if (!pagination) {
3176                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3177                                                            start, end, false);
3178    
3179                                            Collections.sort(list);
3180    
3181                                            list = Collections.unmodifiableList(list);
3182                                    }
3183                                    else {
3184                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3185                                                            start, end);
3186                                    }
3187    
3188                                    cacheResult(list);
3189    
3190                                    finderCache.putResult(finderPath, finderArgs, list);
3191                            }
3192                            catch (Exception e) {
3193                                    finderCache.removeResult(finderPath, finderArgs);
3194    
3195                                    throw processException(e);
3196                            }
3197                            finally {
3198                                    closeSession(session);
3199                            }
3200                    }
3201    
3202                    return list;
3203            }
3204    
3205            /**
3206             * Returns the first social request in the ordered set where userId = &#63; and status = &#63;.
3207             *
3208             * @param userId the user ID
3209             * @param status the status
3210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3211             * @return the first matching social request
3212             * @throws NoSuchRequestException if a matching social request could not be found
3213             */
3214            @Override
3215            public SocialRequest findByU_S_First(long userId, int status,
3216                    OrderByComparator<SocialRequest> orderByComparator)
3217                    throws NoSuchRequestException {
3218                    SocialRequest socialRequest = fetchByU_S_First(userId, status,
3219                                    orderByComparator);
3220    
3221                    if (socialRequest != null) {
3222                            return socialRequest;
3223                    }
3224    
3225                    StringBundler msg = new StringBundler(6);
3226    
3227                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3228    
3229                    msg.append("userId=");
3230                    msg.append(userId);
3231    
3232                    msg.append(", status=");
3233                    msg.append(status);
3234    
3235                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3236    
3237                    throw new NoSuchRequestException(msg.toString());
3238            }
3239    
3240            /**
3241             * Returns the first social request in the ordered set where userId = &#63; and status = &#63;.
3242             *
3243             * @param userId the user ID
3244             * @param status the status
3245             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3246             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
3247             */
3248            @Override
3249            public SocialRequest fetchByU_S_First(long userId, int status,
3250                    OrderByComparator<SocialRequest> orderByComparator) {
3251                    List<SocialRequest> list = findByU_S(userId, status, 0, 1,
3252                                    orderByComparator);
3253    
3254                    if (!list.isEmpty()) {
3255                            return list.get(0);
3256                    }
3257    
3258                    return null;
3259            }
3260    
3261            /**
3262             * Returns the last social request in the ordered set where userId = &#63; and status = &#63;.
3263             *
3264             * @param userId the user ID
3265             * @param status the status
3266             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3267             * @return the last matching social request
3268             * @throws NoSuchRequestException if a matching social request could not be found
3269             */
3270            @Override
3271            public SocialRequest findByU_S_Last(long userId, int status,
3272                    OrderByComparator<SocialRequest> orderByComparator)
3273                    throws NoSuchRequestException {
3274                    SocialRequest socialRequest = fetchByU_S_Last(userId, status,
3275                                    orderByComparator);
3276    
3277                    if (socialRequest != null) {
3278                            return socialRequest;
3279                    }
3280    
3281                    StringBundler msg = new StringBundler(6);
3282    
3283                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3284    
3285                    msg.append("userId=");
3286                    msg.append(userId);
3287    
3288                    msg.append(", status=");
3289                    msg.append(status);
3290    
3291                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3292    
3293                    throw new NoSuchRequestException(msg.toString());
3294            }
3295    
3296            /**
3297             * Returns the last social request in the ordered set where userId = &#63; and status = &#63;.
3298             *
3299             * @param userId the user ID
3300             * @param status the status
3301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3302             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
3303             */
3304            @Override
3305            public SocialRequest fetchByU_S_Last(long userId, int status,
3306                    OrderByComparator<SocialRequest> orderByComparator) {
3307                    int count = countByU_S(userId, status);
3308    
3309                    if (count == 0) {
3310                            return null;
3311                    }
3312    
3313                    List<SocialRequest> list = findByU_S(userId, status, count - 1, count,
3314                                    orderByComparator);
3315    
3316                    if (!list.isEmpty()) {
3317                            return list.get(0);
3318                    }
3319    
3320                    return null;
3321            }
3322    
3323            /**
3324             * Returns the social requests before and after the current social request in the ordered set where userId = &#63; and status = &#63;.
3325             *
3326             * @param requestId the primary key of the current social request
3327             * @param userId the user ID
3328             * @param status the status
3329             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3330             * @return the previous, current, and next social request
3331             * @throws NoSuchRequestException if a social request with the primary key could not be found
3332             */
3333            @Override
3334            public SocialRequest[] findByU_S_PrevAndNext(long requestId, long userId,
3335                    int status, OrderByComparator<SocialRequest> orderByComparator)
3336                    throws NoSuchRequestException {
3337                    SocialRequest socialRequest = findByPrimaryKey(requestId);
3338    
3339                    Session session = null;
3340    
3341                    try {
3342                            session = openSession();
3343    
3344                            SocialRequest[] array = new SocialRequestImpl[3];
3345    
3346                            array[0] = getByU_S_PrevAndNext(session, socialRequest, userId,
3347                                            status, orderByComparator, true);
3348    
3349                            array[1] = socialRequest;
3350    
3351                            array[2] = getByU_S_PrevAndNext(session, socialRequest, userId,
3352                                            status, orderByComparator, false);
3353    
3354                            return array;
3355                    }
3356                    catch (Exception e) {
3357                            throw processException(e);
3358                    }
3359                    finally {
3360                            closeSession(session);
3361                    }
3362            }
3363    
3364            protected SocialRequest getByU_S_PrevAndNext(Session session,
3365                    SocialRequest socialRequest, long userId, int status,
3366                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
3367                    StringBundler query = null;
3368    
3369                    if (orderByComparator != null) {
3370                            query = new StringBundler(5 +
3371                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3372                                            (orderByComparator.getOrderByFields().length * 3));
3373                    }
3374                    else {
3375                            query = new StringBundler(4);
3376                    }
3377    
3378                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3379    
3380                    query.append(_FINDER_COLUMN_U_S_USERID_2);
3381    
3382                    query.append(_FINDER_COLUMN_U_S_STATUS_2);
3383    
3384                    if (orderByComparator != null) {
3385                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3386    
3387                            if (orderByConditionFields.length > 0) {
3388                                    query.append(WHERE_AND);
3389                            }
3390    
3391                            for (int i = 0; i < orderByConditionFields.length; i++) {
3392                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3393                                    query.append(orderByConditionFields[i]);
3394    
3395                                    if ((i + 1) < orderByConditionFields.length) {
3396                                            if (orderByComparator.isAscending() ^ previous) {
3397                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3398                                            }
3399                                            else {
3400                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3401                                            }
3402                                    }
3403                                    else {
3404                                            if (orderByComparator.isAscending() ^ previous) {
3405                                                    query.append(WHERE_GREATER_THAN);
3406                                            }
3407                                            else {
3408                                                    query.append(WHERE_LESSER_THAN);
3409                                            }
3410                                    }
3411                            }
3412    
3413                            query.append(ORDER_BY_CLAUSE);
3414    
3415                            String[] orderByFields = orderByComparator.getOrderByFields();
3416    
3417                            for (int i = 0; i < orderByFields.length; i++) {
3418                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3419                                    query.append(orderByFields[i]);
3420    
3421                                    if ((i + 1) < orderByFields.length) {
3422                                            if (orderByComparator.isAscending() ^ previous) {
3423                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3424                                            }
3425                                            else {
3426                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3427                                            }
3428                                    }
3429                                    else {
3430                                            if (orderByComparator.isAscending() ^ previous) {
3431                                                    query.append(ORDER_BY_ASC);
3432                                            }
3433                                            else {
3434                                                    query.append(ORDER_BY_DESC);
3435                                            }
3436                                    }
3437                            }
3438                    }
3439                    else {
3440                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3441                    }
3442    
3443                    String sql = query.toString();
3444    
3445                    Query q = session.createQuery(sql);
3446    
3447                    q.setFirstResult(0);
3448                    q.setMaxResults(2);
3449    
3450                    QueryPos qPos = QueryPos.getInstance(q);
3451    
3452                    qPos.add(userId);
3453    
3454                    qPos.add(status);
3455    
3456                    if (orderByComparator != null) {
3457                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
3458    
3459                            for (Object value : values) {
3460                                    qPos.add(value);
3461                            }
3462                    }
3463    
3464                    List<SocialRequest> list = q.list();
3465    
3466                    if (list.size() == 2) {
3467                            return list.get(1);
3468                    }
3469                    else {
3470                            return null;
3471                    }
3472            }
3473    
3474            /**
3475             * Removes all the social requests where userId = &#63; and status = &#63; from the database.
3476             *
3477             * @param userId the user ID
3478             * @param status the status
3479             */
3480            @Override
3481            public void removeByU_S(long userId, int status) {
3482                    for (SocialRequest socialRequest : findByU_S(userId, status,
3483                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3484                            remove(socialRequest);
3485                    }
3486            }
3487    
3488            /**
3489             * Returns the number of social requests where userId = &#63; and status = &#63;.
3490             *
3491             * @param userId the user ID
3492             * @param status the status
3493             * @return the number of matching social requests
3494             */
3495            @Override
3496            public int countByU_S(long userId, int status) {
3497                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_S;
3498    
3499                    Object[] finderArgs = new Object[] { userId, status };
3500    
3501                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3502    
3503                    if (count == null) {
3504                            StringBundler query = new StringBundler(3);
3505    
3506                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
3507    
3508                            query.append(_FINDER_COLUMN_U_S_USERID_2);
3509    
3510                            query.append(_FINDER_COLUMN_U_S_STATUS_2);
3511    
3512                            String sql = query.toString();
3513    
3514                            Session session = null;
3515    
3516                            try {
3517                                    session = openSession();
3518    
3519                                    Query q = session.createQuery(sql);
3520    
3521                                    QueryPos qPos = QueryPos.getInstance(q);
3522    
3523                                    qPos.add(userId);
3524    
3525                                    qPos.add(status);
3526    
3527                                    count = (Long)q.uniqueResult();
3528    
3529                                    finderCache.putResult(finderPath, finderArgs, count);
3530                            }
3531                            catch (Exception e) {
3532                                    finderCache.removeResult(finderPath, finderArgs);
3533    
3534                                    throw processException(e);
3535                            }
3536                            finally {
3537                                    closeSession(session);
3538                            }
3539                    }
3540    
3541                    return count.intValue();
3542            }
3543    
3544            private static final String _FINDER_COLUMN_U_S_USERID_2 = "socialRequest.userId = ? AND ";
3545            private static final String _FINDER_COLUMN_U_S_STATUS_2 = "socialRequest.status = ?";
3546            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3547                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
3548                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
3549                            "findByC_C",
3550                            new String[] {
3551                                    Long.class.getName(), Long.class.getName(),
3552                                    
3553                            Integer.class.getName(), Integer.class.getName(),
3554                                    OrderByComparator.class.getName()
3555                            });
3556            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3557                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
3558                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
3559                            "findByC_C",
3560                            new String[] { Long.class.getName(), Long.class.getName() },
3561                            SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3562                            SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK);
3563            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
3564                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
3565                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
3566                            new String[] { Long.class.getName(), Long.class.getName() });
3567    
3568            /**
3569             * Returns all the social requests where classNameId = &#63; and classPK = &#63;.
3570             *
3571             * @param classNameId the class name ID
3572             * @param classPK the class p k
3573             * @return the matching social requests
3574             */
3575            @Override
3576            public List<SocialRequest> findByC_C(long classNameId, long classPK) {
3577                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
3578                            QueryUtil.ALL_POS, null);
3579            }
3580    
3581            /**
3582             * Returns a range of all the social requests where classNameId = &#63; and classPK = &#63;.
3583             *
3584             * <p>
3585             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3586             * </p>
3587             *
3588             * @param classNameId the class name ID
3589             * @param classPK the class p k
3590             * @param start the lower bound of the range of social requests
3591             * @param end the upper bound of the range of social requests (not inclusive)
3592             * @return the range of matching social requests
3593             */
3594            @Override
3595            public List<SocialRequest> findByC_C(long classNameId, long classPK,
3596                    int start, int end) {
3597                    return findByC_C(classNameId, classPK, start, end, null);
3598            }
3599    
3600            /**
3601             * Returns an ordered range of all the social requests where classNameId = &#63; and classPK = &#63;.
3602             *
3603             * <p>
3604             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3605             * </p>
3606             *
3607             * @param classNameId the class name ID
3608             * @param classPK the class p k
3609             * @param start the lower bound of the range of social requests
3610             * @param end the upper bound of the range of social requests (not inclusive)
3611             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3612             * @return the ordered range of matching social requests
3613             */
3614            @Override
3615            public List<SocialRequest> findByC_C(long classNameId, long classPK,
3616                    int start, int end, OrderByComparator<SocialRequest> orderByComparator) {
3617                    return findByC_C(classNameId, classPK, start, end, orderByComparator,
3618                            true);
3619            }
3620    
3621            /**
3622             * Returns an ordered range of all the social requests where classNameId = &#63; and classPK = &#63;.
3623             *
3624             * <p>
3625             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3626             * </p>
3627             *
3628             * @param classNameId the class name ID
3629             * @param classPK the class p k
3630             * @param start the lower bound of the range of social requests
3631             * @param end the upper bound of the range of social requests (not inclusive)
3632             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3633             * @param retrieveFromCache whether to retrieve from the finder cache
3634             * @return the ordered range of matching social requests
3635             */
3636            @Override
3637            public List<SocialRequest> findByC_C(long classNameId, long classPK,
3638                    int start, int end, OrderByComparator<SocialRequest> orderByComparator,
3639                    boolean retrieveFromCache) {
3640                    boolean pagination = true;
3641                    FinderPath finderPath = null;
3642                    Object[] finderArgs = null;
3643    
3644                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3645                                    (orderByComparator == null)) {
3646                            pagination = false;
3647                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
3648                            finderArgs = new Object[] { classNameId, classPK };
3649                    }
3650                    else {
3651                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
3652                            finderArgs = new Object[] {
3653                                            classNameId, classPK,
3654                                            
3655                                            start, end, orderByComparator
3656                                    };
3657                    }
3658    
3659                    List<SocialRequest> list = null;
3660    
3661                    if (retrieveFromCache) {
3662                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
3663                                            finderArgs, this);
3664    
3665                            if ((list != null) && !list.isEmpty()) {
3666                                    for (SocialRequest socialRequest : list) {
3667                                            if ((classNameId != socialRequest.getClassNameId()) ||
3668                                                            (classPK != socialRequest.getClassPK())) {
3669                                                    list = null;
3670    
3671                                                    break;
3672                                            }
3673                                    }
3674                            }
3675                    }
3676    
3677                    if (list == null) {
3678                            StringBundler query = null;
3679    
3680                            if (orderByComparator != null) {
3681                                    query = new StringBundler(4 +
3682                                                    (orderByComparator.getOrderByFields().length * 2));
3683                            }
3684                            else {
3685                                    query = new StringBundler(4);
3686                            }
3687    
3688                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3689    
3690                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3691    
3692                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3693    
3694                            if (orderByComparator != null) {
3695                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3696                                            orderByComparator);
3697                            }
3698                            else
3699                             if (pagination) {
3700                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3701                            }
3702    
3703                            String sql = query.toString();
3704    
3705                            Session session = null;
3706    
3707                            try {
3708                                    session = openSession();
3709    
3710                                    Query q = session.createQuery(sql);
3711    
3712                                    QueryPos qPos = QueryPos.getInstance(q);
3713    
3714                                    qPos.add(classNameId);
3715    
3716                                    qPos.add(classPK);
3717    
3718                                    if (!pagination) {
3719                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3720                                                            start, end, false);
3721    
3722                                            Collections.sort(list);
3723    
3724                                            list = Collections.unmodifiableList(list);
3725                                    }
3726                                    else {
3727                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
3728                                                            start, end);
3729                                    }
3730    
3731                                    cacheResult(list);
3732    
3733                                    finderCache.putResult(finderPath, finderArgs, list);
3734                            }
3735                            catch (Exception e) {
3736                                    finderCache.removeResult(finderPath, finderArgs);
3737    
3738                                    throw processException(e);
3739                            }
3740                            finally {
3741                                    closeSession(session);
3742                            }
3743                    }
3744    
3745                    return list;
3746            }
3747    
3748            /**
3749             * Returns the first social request in the ordered set where classNameId = &#63; and classPK = &#63;.
3750             *
3751             * @param classNameId the class name ID
3752             * @param classPK the class p k
3753             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3754             * @return the first matching social request
3755             * @throws NoSuchRequestException if a matching social request could not be found
3756             */
3757            @Override
3758            public SocialRequest findByC_C_First(long classNameId, long classPK,
3759                    OrderByComparator<SocialRequest> orderByComparator)
3760                    throws NoSuchRequestException {
3761                    SocialRequest socialRequest = fetchByC_C_First(classNameId, classPK,
3762                                    orderByComparator);
3763    
3764                    if (socialRequest != null) {
3765                            return socialRequest;
3766                    }
3767    
3768                    StringBundler msg = new StringBundler(6);
3769    
3770                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3771    
3772                    msg.append("classNameId=");
3773                    msg.append(classNameId);
3774    
3775                    msg.append(", classPK=");
3776                    msg.append(classPK);
3777    
3778                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3779    
3780                    throw new NoSuchRequestException(msg.toString());
3781            }
3782    
3783            /**
3784             * Returns the first social request in the ordered set where classNameId = &#63; and classPK = &#63;.
3785             *
3786             * @param classNameId the class name ID
3787             * @param classPK the class p k
3788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3789             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
3790             */
3791            @Override
3792            public SocialRequest fetchByC_C_First(long classNameId, long classPK,
3793                    OrderByComparator<SocialRequest> orderByComparator) {
3794                    List<SocialRequest> list = findByC_C(classNameId, classPK, 0, 1,
3795                                    orderByComparator);
3796    
3797                    if (!list.isEmpty()) {
3798                            return list.get(0);
3799                    }
3800    
3801                    return null;
3802            }
3803    
3804            /**
3805             * Returns the last social request in the ordered set where classNameId = &#63; and classPK = &#63;.
3806             *
3807             * @param classNameId the class name ID
3808             * @param classPK the class p k
3809             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3810             * @return the last matching social request
3811             * @throws NoSuchRequestException if a matching social request could not be found
3812             */
3813            @Override
3814            public SocialRequest findByC_C_Last(long classNameId, long classPK,
3815                    OrderByComparator<SocialRequest> orderByComparator)
3816                    throws NoSuchRequestException {
3817                    SocialRequest socialRequest = fetchByC_C_Last(classNameId, classPK,
3818                                    orderByComparator);
3819    
3820                    if (socialRequest != null) {
3821                            return socialRequest;
3822                    }
3823    
3824                    StringBundler msg = new StringBundler(6);
3825    
3826                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3827    
3828                    msg.append("classNameId=");
3829                    msg.append(classNameId);
3830    
3831                    msg.append(", classPK=");
3832                    msg.append(classPK);
3833    
3834                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3835    
3836                    throw new NoSuchRequestException(msg.toString());
3837            }
3838    
3839            /**
3840             * Returns the last social request in the ordered set where classNameId = &#63; and classPK = &#63;.
3841             *
3842             * @param classNameId the class name ID
3843             * @param classPK the class p k
3844             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3845             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
3846             */
3847            @Override
3848            public SocialRequest fetchByC_C_Last(long classNameId, long classPK,
3849                    OrderByComparator<SocialRequest> orderByComparator) {
3850                    int count = countByC_C(classNameId, classPK);
3851    
3852                    if (count == 0) {
3853                            return null;
3854                    }
3855    
3856                    List<SocialRequest> list = findByC_C(classNameId, classPK, count - 1,
3857                                    count, orderByComparator);
3858    
3859                    if (!list.isEmpty()) {
3860                            return list.get(0);
3861                    }
3862    
3863                    return null;
3864            }
3865    
3866            /**
3867             * Returns the social requests before and after the current social request in the ordered set where classNameId = &#63; and classPK = &#63;.
3868             *
3869             * @param requestId the primary key of the current social request
3870             * @param classNameId the class name ID
3871             * @param classPK the class p k
3872             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3873             * @return the previous, current, and next social request
3874             * @throws NoSuchRequestException if a social request with the primary key could not be found
3875             */
3876            @Override
3877            public SocialRequest[] findByC_C_PrevAndNext(long requestId,
3878                    long classNameId, long classPK,
3879                    OrderByComparator<SocialRequest> orderByComparator)
3880                    throws NoSuchRequestException {
3881                    SocialRequest socialRequest = findByPrimaryKey(requestId);
3882    
3883                    Session session = null;
3884    
3885                    try {
3886                            session = openSession();
3887    
3888                            SocialRequest[] array = new SocialRequestImpl[3];
3889    
3890                            array[0] = getByC_C_PrevAndNext(session, socialRequest,
3891                                            classNameId, classPK, orderByComparator, true);
3892    
3893                            array[1] = socialRequest;
3894    
3895                            array[2] = getByC_C_PrevAndNext(session, socialRequest,
3896                                            classNameId, classPK, orderByComparator, false);
3897    
3898                            return array;
3899                    }
3900                    catch (Exception e) {
3901                            throw processException(e);
3902                    }
3903                    finally {
3904                            closeSession(session);
3905                    }
3906            }
3907    
3908            protected SocialRequest getByC_C_PrevAndNext(Session session,
3909                    SocialRequest socialRequest, long classNameId, long classPK,
3910                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
3911                    StringBundler query = null;
3912    
3913                    if (orderByComparator != null) {
3914                            query = new StringBundler(5 +
3915                                            (orderByComparator.getOrderByConditionFields().length * 3) +
3916                                            (orderByComparator.getOrderByFields().length * 3));
3917                    }
3918                    else {
3919                            query = new StringBundler(4);
3920                    }
3921    
3922                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
3923    
3924                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
3925    
3926                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
3927    
3928                    if (orderByComparator != null) {
3929                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3930    
3931                            if (orderByConditionFields.length > 0) {
3932                                    query.append(WHERE_AND);
3933                            }
3934    
3935                            for (int i = 0; i < orderByConditionFields.length; i++) {
3936                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3937                                    query.append(orderByConditionFields[i]);
3938    
3939                                    if ((i + 1) < orderByConditionFields.length) {
3940                                            if (orderByComparator.isAscending() ^ previous) {
3941                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3942                                            }
3943                                            else {
3944                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3945                                            }
3946                                    }
3947                                    else {
3948                                            if (orderByComparator.isAscending() ^ previous) {
3949                                                    query.append(WHERE_GREATER_THAN);
3950                                            }
3951                                            else {
3952                                                    query.append(WHERE_LESSER_THAN);
3953                                            }
3954                                    }
3955                            }
3956    
3957                            query.append(ORDER_BY_CLAUSE);
3958    
3959                            String[] orderByFields = orderByComparator.getOrderByFields();
3960    
3961                            for (int i = 0; i < orderByFields.length; i++) {
3962                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3963                                    query.append(orderByFields[i]);
3964    
3965                                    if ((i + 1) < orderByFields.length) {
3966                                            if (orderByComparator.isAscending() ^ previous) {
3967                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3968                                            }
3969                                            else {
3970                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3971                                            }
3972                                    }
3973                                    else {
3974                                            if (orderByComparator.isAscending() ^ previous) {
3975                                                    query.append(ORDER_BY_ASC);
3976                                            }
3977                                            else {
3978                                                    query.append(ORDER_BY_DESC);
3979                                            }
3980                                    }
3981                            }
3982                    }
3983                    else {
3984                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
3985                    }
3986    
3987                    String sql = query.toString();
3988    
3989                    Query q = session.createQuery(sql);
3990    
3991                    q.setFirstResult(0);
3992                    q.setMaxResults(2);
3993    
3994                    QueryPos qPos = QueryPos.getInstance(q);
3995    
3996                    qPos.add(classNameId);
3997    
3998                    qPos.add(classPK);
3999    
4000                    if (orderByComparator != null) {
4001                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
4002    
4003                            for (Object value : values) {
4004                                    qPos.add(value);
4005                            }
4006                    }
4007    
4008                    List<SocialRequest> list = q.list();
4009    
4010                    if (list.size() == 2) {
4011                            return list.get(1);
4012                    }
4013                    else {
4014                            return null;
4015                    }
4016            }
4017    
4018            /**
4019             * Removes all the social requests where classNameId = &#63; and classPK = &#63; from the database.
4020             *
4021             * @param classNameId the class name ID
4022             * @param classPK the class p k
4023             */
4024            @Override
4025            public void removeByC_C(long classNameId, long classPK) {
4026                    for (SocialRequest socialRequest : findByC_C(classNameId, classPK,
4027                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4028                            remove(socialRequest);
4029                    }
4030            }
4031    
4032            /**
4033             * Returns the number of social requests where classNameId = &#63; and classPK = &#63;.
4034             *
4035             * @param classNameId the class name ID
4036             * @param classPK the class p k
4037             * @return the number of matching social requests
4038             */
4039            @Override
4040            public int countByC_C(long classNameId, long classPK) {
4041                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
4042    
4043                    Object[] finderArgs = new Object[] { classNameId, classPK };
4044    
4045                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4046    
4047                    if (count == null) {
4048                            StringBundler query = new StringBundler(3);
4049    
4050                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
4051    
4052                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
4053    
4054                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
4055    
4056                            String sql = query.toString();
4057    
4058                            Session session = null;
4059    
4060                            try {
4061                                    session = openSession();
4062    
4063                                    Query q = session.createQuery(sql);
4064    
4065                                    QueryPos qPos = QueryPos.getInstance(q);
4066    
4067                                    qPos.add(classNameId);
4068    
4069                                    qPos.add(classPK);
4070    
4071                                    count = (Long)q.uniqueResult();
4072    
4073                                    finderCache.putResult(finderPath, finderArgs, count);
4074                            }
4075                            catch (Exception e) {
4076                                    finderCache.removeResult(finderPath, finderArgs);
4077    
4078                                    throw processException(e);
4079                            }
4080                            finally {
4081                                    closeSession(session);
4082                            }
4083                    }
4084    
4085                    return count.intValue();
4086            }
4087    
4088            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
4089            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "socialRequest.classPK = ?";
4090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4091                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
4092                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4093                            "findByR_S",
4094                            new String[] {
4095                                    Long.class.getName(), Integer.class.getName(),
4096                                    
4097                            Integer.class.getName(), Integer.class.getName(),
4098                                    OrderByComparator.class.getName()
4099                            });
4100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4101                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
4102                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4103                            "findByR_S",
4104                            new String[] { Long.class.getName(), Integer.class.getName() },
4105                            SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK |
4106                            SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
4107            public static final FinderPath FINDER_PATH_COUNT_BY_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4108                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
4109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_S",
4110                            new String[] { Long.class.getName(), Integer.class.getName() });
4111    
4112            /**
4113             * Returns all the social requests where receiverUserId = &#63; and status = &#63;.
4114             *
4115             * @param receiverUserId the receiver user ID
4116             * @param status the status
4117             * @return the matching social requests
4118             */
4119            @Override
4120            public List<SocialRequest> findByR_S(long receiverUserId, int status) {
4121                    return findByR_S(receiverUserId, status, QueryUtil.ALL_POS,
4122                            QueryUtil.ALL_POS, null);
4123            }
4124    
4125            /**
4126             * Returns a range of all the social requests where receiverUserId = &#63; and status = &#63;.
4127             *
4128             * <p>
4129             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4130             * </p>
4131             *
4132             * @param receiverUserId the receiver user ID
4133             * @param status the status
4134             * @param start the lower bound of the range of social requests
4135             * @param end the upper bound of the range of social requests (not inclusive)
4136             * @return the range of matching social requests
4137             */
4138            @Override
4139            public List<SocialRequest> findByR_S(long receiverUserId, int status,
4140                    int start, int end) {
4141                    return findByR_S(receiverUserId, status, start, end, null);
4142            }
4143    
4144            /**
4145             * Returns an ordered range of all the social requests where receiverUserId = &#63; and status = &#63;.
4146             *
4147             * <p>
4148             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4149             * </p>
4150             *
4151             * @param receiverUserId the receiver user ID
4152             * @param status the status
4153             * @param start the lower bound of the range of social requests
4154             * @param end the upper bound of the range of social requests (not inclusive)
4155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4156             * @return the ordered range of matching social requests
4157             */
4158            @Override
4159            public List<SocialRequest> findByR_S(long receiverUserId, int status,
4160                    int start, int end, OrderByComparator<SocialRequest> orderByComparator) {
4161                    return findByR_S(receiverUserId, status, start, end, orderByComparator,
4162                            true);
4163            }
4164    
4165            /**
4166             * Returns an ordered range of all the social requests where receiverUserId = &#63; and status = &#63;.
4167             *
4168             * <p>
4169             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4170             * </p>
4171             *
4172             * @param receiverUserId the receiver user ID
4173             * @param status the status
4174             * @param start the lower bound of the range of social requests
4175             * @param end the upper bound of the range of social requests (not inclusive)
4176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4177             * @param retrieveFromCache whether to retrieve from the finder cache
4178             * @return the ordered range of matching social requests
4179             */
4180            @Override
4181            public List<SocialRequest> findByR_S(long receiverUserId, int status,
4182                    int start, int end, OrderByComparator<SocialRequest> orderByComparator,
4183                    boolean retrieveFromCache) {
4184                    boolean pagination = true;
4185                    FinderPath finderPath = null;
4186                    Object[] finderArgs = null;
4187    
4188                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4189                                    (orderByComparator == null)) {
4190                            pagination = false;
4191                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S;
4192                            finderArgs = new Object[] { receiverUserId, status };
4193                    }
4194                    else {
4195                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_R_S;
4196                            finderArgs = new Object[] {
4197                                            receiverUserId, status,
4198                                            
4199                                            start, end, orderByComparator
4200                                    };
4201                    }
4202    
4203                    List<SocialRequest> list = null;
4204    
4205                    if (retrieveFromCache) {
4206                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
4207                                            finderArgs, this);
4208    
4209                            if ((list != null) && !list.isEmpty()) {
4210                                    for (SocialRequest socialRequest : list) {
4211                                            if ((receiverUserId != socialRequest.getReceiverUserId()) ||
4212                                                            (status != socialRequest.getStatus())) {
4213                                                    list = null;
4214    
4215                                                    break;
4216                                            }
4217                                    }
4218                            }
4219                    }
4220    
4221                    if (list == null) {
4222                            StringBundler query = null;
4223    
4224                            if (orderByComparator != null) {
4225                                    query = new StringBundler(4 +
4226                                                    (orderByComparator.getOrderByFields().length * 2));
4227                            }
4228                            else {
4229                                    query = new StringBundler(4);
4230                            }
4231    
4232                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4233    
4234                            query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
4235    
4236                            query.append(_FINDER_COLUMN_R_S_STATUS_2);
4237    
4238                            if (orderByComparator != null) {
4239                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4240                                            orderByComparator);
4241                            }
4242                            else
4243                             if (pagination) {
4244                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
4245                            }
4246    
4247                            String sql = query.toString();
4248    
4249                            Session session = null;
4250    
4251                            try {
4252                                    session = openSession();
4253    
4254                                    Query q = session.createQuery(sql);
4255    
4256                                    QueryPos qPos = QueryPos.getInstance(q);
4257    
4258                                    qPos.add(receiverUserId);
4259    
4260                                    qPos.add(status);
4261    
4262                                    if (!pagination) {
4263                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
4264                                                            start, end, false);
4265    
4266                                            Collections.sort(list);
4267    
4268                                            list = Collections.unmodifiableList(list);
4269                                    }
4270                                    else {
4271                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
4272                                                            start, end);
4273                                    }
4274    
4275                                    cacheResult(list);
4276    
4277                                    finderCache.putResult(finderPath, finderArgs, list);
4278                            }
4279                            catch (Exception e) {
4280                                    finderCache.removeResult(finderPath, finderArgs);
4281    
4282                                    throw processException(e);
4283                            }
4284                            finally {
4285                                    closeSession(session);
4286                            }
4287                    }
4288    
4289                    return list;
4290            }
4291    
4292            /**
4293             * Returns the first social request in the ordered set where receiverUserId = &#63; and status = &#63;.
4294             *
4295             * @param receiverUserId the receiver user ID
4296             * @param status the status
4297             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4298             * @return the first matching social request
4299             * @throws NoSuchRequestException if a matching social request could not be found
4300             */
4301            @Override
4302            public SocialRequest findByR_S_First(long receiverUserId, int status,
4303                    OrderByComparator<SocialRequest> orderByComparator)
4304                    throws NoSuchRequestException {
4305                    SocialRequest socialRequest = fetchByR_S_First(receiverUserId, status,
4306                                    orderByComparator);
4307    
4308                    if (socialRequest != null) {
4309                            return socialRequest;
4310                    }
4311    
4312                    StringBundler msg = new StringBundler(6);
4313    
4314                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4315    
4316                    msg.append("receiverUserId=");
4317                    msg.append(receiverUserId);
4318    
4319                    msg.append(", status=");
4320                    msg.append(status);
4321    
4322                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4323    
4324                    throw new NoSuchRequestException(msg.toString());
4325            }
4326    
4327            /**
4328             * Returns the first social request in the ordered set where receiverUserId = &#63; and status = &#63;.
4329             *
4330             * @param receiverUserId the receiver user ID
4331             * @param status the status
4332             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4333             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
4334             */
4335            @Override
4336            public SocialRequest fetchByR_S_First(long receiverUserId, int status,
4337                    OrderByComparator<SocialRequest> orderByComparator) {
4338                    List<SocialRequest> list = findByR_S(receiverUserId, status, 0, 1,
4339                                    orderByComparator);
4340    
4341                    if (!list.isEmpty()) {
4342                            return list.get(0);
4343                    }
4344    
4345                    return null;
4346            }
4347    
4348            /**
4349             * Returns the last social request in the ordered set where receiverUserId = &#63; and status = &#63;.
4350             *
4351             * @param receiverUserId the receiver user ID
4352             * @param status the status
4353             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4354             * @return the last matching social request
4355             * @throws NoSuchRequestException if a matching social request could not be found
4356             */
4357            @Override
4358            public SocialRequest findByR_S_Last(long receiverUserId, int status,
4359                    OrderByComparator<SocialRequest> orderByComparator)
4360                    throws NoSuchRequestException {
4361                    SocialRequest socialRequest = fetchByR_S_Last(receiverUserId, status,
4362                                    orderByComparator);
4363    
4364                    if (socialRequest != null) {
4365                            return socialRequest;
4366                    }
4367    
4368                    StringBundler msg = new StringBundler(6);
4369    
4370                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4371    
4372                    msg.append("receiverUserId=");
4373                    msg.append(receiverUserId);
4374    
4375                    msg.append(", status=");
4376                    msg.append(status);
4377    
4378                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4379    
4380                    throw new NoSuchRequestException(msg.toString());
4381            }
4382    
4383            /**
4384             * Returns the last social request in the ordered set where receiverUserId = &#63; and status = &#63;.
4385             *
4386             * @param receiverUserId the receiver user ID
4387             * @param status the status
4388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4389             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
4390             */
4391            @Override
4392            public SocialRequest fetchByR_S_Last(long receiverUserId, int status,
4393                    OrderByComparator<SocialRequest> orderByComparator) {
4394                    int count = countByR_S(receiverUserId, status);
4395    
4396                    if (count == 0) {
4397                            return null;
4398                    }
4399    
4400                    List<SocialRequest> list = findByR_S(receiverUserId, status, count - 1,
4401                                    count, orderByComparator);
4402    
4403                    if (!list.isEmpty()) {
4404                            return list.get(0);
4405                    }
4406    
4407                    return null;
4408            }
4409    
4410            /**
4411             * Returns the social requests before and after the current social request in the ordered set where receiverUserId = &#63; and status = &#63;.
4412             *
4413             * @param requestId the primary key of the current social request
4414             * @param receiverUserId the receiver user ID
4415             * @param status the status
4416             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4417             * @return the previous, current, and next social request
4418             * @throws NoSuchRequestException if a social request with the primary key could not be found
4419             */
4420            @Override
4421            public SocialRequest[] findByR_S_PrevAndNext(long requestId,
4422                    long receiverUserId, int status,
4423                    OrderByComparator<SocialRequest> orderByComparator)
4424                    throws NoSuchRequestException {
4425                    SocialRequest socialRequest = findByPrimaryKey(requestId);
4426    
4427                    Session session = null;
4428    
4429                    try {
4430                            session = openSession();
4431    
4432                            SocialRequest[] array = new SocialRequestImpl[3];
4433    
4434                            array[0] = getByR_S_PrevAndNext(session, socialRequest,
4435                                            receiverUserId, status, orderByComparator, true);
4436    
4437                            array[1] = socialRequest;
4438    
4439                            array[2] = getByR_S_PrevAndNext(session, socialRequest,
4440                                            receiverUserId, status, orderByComparator, false);
4441    
4442                            return array;
4443                    }
4444                    catch (Exception e) {
4445                            throw processException(e);
4446                    }
4447                    finally {
4448                            closeSession(session);
4449                    }
4450            }
4451    
4452            protected SocialRequest getByR_S_PrevAndNext(Session session,
4453                    SocialRequest socialRequest, long receiverUserId, int status,
4454                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
4455                    StringBundler query = null;
4456    
4457                    if (orderByComparator != null) {
4458                            query = new StringBundler(5 +
4459                                            (orderByComparator.getOrderByConditionFields().length * 3) +
4460                                            (orderByComparator.getOrderByFields().length * 3));
4461                    }
4462                    else {
4463                            query = new StringBundler(4);
4464                    }
4465    
4466                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4467    
4468                    query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
4469    
4470                    query.append(_FINDER_COLUMN_R_S_STATUS_2);
4471    
4472                    if (orderByComparator != null) {
4473                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4474    
4475                            if (orderByConditionFields.length > 0) {
4476                                    query.append(WHERE_AND);
4477                            }
4478    
4479                            for (int i = 0; i < orderByConditionFields.length; i++) {
4480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4481                                    query.append(orderByConditionFields[i]);
4482    
4483                                    if ((i + 1) < orderByConditionFields.length) {
4484                                            if (orderByComparator.isAscending() ^ previous) {
4485                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4486                                            }
4487                                            else {
4488                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4489                                            }
4490                                    }
4491                                    else {
4492                                            if (orderByComparator.isAscending() ^ previous) {
4493                                                    query.append(WHERE_GREATER_THAN);
4494                                            }
4495                                            else {
4496                                                    query.append(WHERE_LESSER_THAN);
4497                                            }
4498                                    }
4499                            }
4500    
4501                            query.append(ORDER_BY_CLAUSE);
4502    
4503                            String[] orderByFields = orderByComparator.getOrderByFields();
4504    
4505                            for (int i = 0; i < orderByFields.length; i++) {
4506                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4507                                    query.append(orderByFields[i]);
4508    
4509                                    if ((i + 1) < orderByFields.length) {
4510                                            if (orderByComparator.isAscending() ^ previous) {
4511                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4512                                            }
4513                                            else {
4514                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4515                                            }
4516                                    }
4517                                    else {
4518                                            if (orderByComparator.isAscending() ^ previous) {
4519                                                    query.append(ORDER_BY_ASC);
4520                                            }
4521                                            else {
4522                                                    query.append(ORDER_BY_DESC);
4523                                            }
4524                                    }
4525                            }
4526                    }
4527                    else {
4528                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
4529                    }
4530    
4531                    String sql = query.toString();
4532    
4533                    Query q = session.createQuery(sql);
4534    
4535                    q.setFirstResult(0);
4536                    q.setMaxResults(2);
4537    
4538                    QueryPos qPos = QueryPos.getInstance(q);
4539    
4540                    qPos.add(receiverUserId);
4541    
4542                    qPos.add(status);
4543    
4544                    if (orderByComparator != null) {
4545                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
4546    
4547                            for (Object value : values) {
4548                                    qPos.add(value);
4549                            }
4550                    }
4551    
4552                    List<SocialRequest> list = q.list();
4553    
4554                    if (list.size() == 2) {
4555                            return list.get(1);
4556                    }
4557                    else {
4558                            return null;
4559                    }
4560            }
4561    
4562            /**
4563             * Removes all the social requests where receiverUserId = &#63; and status = &#63; from the database.
4564             *
4565             * @param receiverUserId the receiver user ID
4566             * @param status the status
4567             */
4568            @Override
4569            public void removeByR_S(long receiverUserId, int status) {
4570                    for (SocialRequest socialRequest : findByR_S(receiverUserId, status,
4571                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4572                            remove(socialRequest);
4573                    }
4574            }
4575    
4576            /**
4577             * Returns the number of social requests where receiverUserId = &#63; and status = &#63;.
4578             *
4579             * @param receiverUserId the receiver user ID
4580             * @param status the status
4581             * @return the number of matching social requests
4582             */
4583            @Override
4584            public int countByR_S(long receiverUserId, int status) {
4585                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_S;
4586    
4587                    Object[] finderArgs = new Object[] { receiverUserId, status };
4588    
4589                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4590    
4591                    if (count == null) {
4592                            StringBundler query = new StringBundler(3);
4593    
4594                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
4595    
4596                            query.append(_FINDER_COLUMN_R_S_RECEIVERUSERID_2);
4597    
4598                            query.append(_FINDER_COLUMN_R_S_STATUS_2);
4599    
4600                            String sql = query.toString();
4601    
4602                            Session session = null;
4603    
4604                            try {
4605                                    session = openSession();
4606    
4607                                    Query q = session.createQuery(sql);
4608    
4609                                    QueryPos qPos = QueryPos.getInstance(q);
4610    
4611                                    qPos.add(receiverUserId);
4612    
4613                                    qPos.add(status);
4614    
4615                                    count = (Long)q.uniqueResult();
4616    
4617                                    finderCache.putResult(finderPath, finderArgs, count);
4618                            }
4619                            catch (Exception e) {
4620                                    finderCache.removeResult(finderPath, finderArgs);
4621    
4622                                    throw processException(e);
4623                            }
4624                            finally {
4625                                    closeSession(session);
4626                            }
4627                    }
4628    
4629                    return count.intValue();
4630            }
4631    
4632            private static final String _FINDER_COLUMN_R_S_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ? AND ";
4633            private static final String _FINDER_COLUMN_R_S_STATUS_2 = "socialRequest.status = ?";
4634            public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4635                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
4636                            SocialRequestImpl.class, FINDER_CLASS_NAME_ENTITY,
4637                            "fetchByU_C_C_T_R",
4638                            new String[] {
4639                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4640                                    Integer.class.getName(), Long.class.getName()
4641                            },
4642                            SocialRequestModelImpl.USERID_COLUMN_BITMASK |
4643                            SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4644                            SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK |
4645                            SocialRequestModelImpl.TYPE_COLUMN_BITMASK |
4646                            SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK);
4647            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_R = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4648                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
4649                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_T_R",
4650                            new String[] {
4651                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4652                                    Integer.class.getName(), Long.class.getName()
4653                            });
4654    
4655            /**
4656             * Returns the social request where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; or throws a {@link NoSuchRequestException} if it could not be found.
4657             *
4658             * @param userId the user ID
4659             * @param classNameId the class name ID
4660             * @param classPK the class p k
4661             * @param type the type
4662             * @param receiverUserId the receiver user ID
4663             * @return the matching social request
4664             * @throws NoSuchRequestException if a matching social request could not be found
4665             */
4666            @Override
4667            public SocialRequest findByU_C_C_T_R(long userId, long classNameId,
4668                    long classPK, int type, long receiverUserId)
4669                    throws NoSuchRequestException {
4670                    SocialRequest socialRequest = fetchByU_C_C_T_R(userId, classNameId,
4671                                    classPK, type, receiverUserId);
4672    
4673                    if (socialRequest == null) {
4674                            StringBundler msg = new StringBundler(12);
4675    
4676                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4677    
4678                            msg.append("userId=");
4679                            msg.append(userId);
4680    
4681                            msg.append(", classNameId=");
4682                            msg.append(classNameId);
4683    
4684                            msg.append(", classPK=");
4685                            msg.append(classPK);
4686    
4687                            msg.append(", type=");
4688                            msg.append(type);
4689    
4690                            msg.append(", receiverUserId=");
4691                            msg.append(receiverUserId);
4692    
4693                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4694    
4695                            if (_log.isDebugEnabled()) {
4696                                    _log.debug(msg.toString());
4697                            }
4698    
4699                            throw new NoSuchRequestException(msg.toString());
4700                    }
4701    
4702                    return socialRequest;
4703            }
4704    
4705            /**
4706             * Returns the social request where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4707             *
4708             * @param userId the user ID
4709             * @param classNameId the class name ID
4710             * @param classPK the class p k
4711             * @param type the type
4712             * @param receiverUserId the receiver user ID
4713             * @return the matching social request, or <code>null</code> if a matching social request could not be found
4714             */
4715            @Override
4716            public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
4717                    long classPK, int type, long receiverUserId) {
4718                    return fetchByU_C_C_T_R(userId, classNameId, classPK, type,
4719                            receiverUserId, true);
4720            }
4721    
4722            /**
4723             * Returns the social request where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4724             *
4725             * @param userId the user ID
4726             * @param classNameId the class name ID
4727             * @param classPK the class p k
4728             * @param type the type
4729             * @param receiverUserId the receiver user ID
4730             * @param retrieveFromCache whether to retrieve from the finder cache
4731             * @return the matching social request, or <code>null</code> if a matching social request could not be found
4732             */
4733            @Override
4734            public SocialRequest fetchByU_C_C_T_R(long userId, long classNameId,
4735                    long classPK, int type, long receiverUserId, boolean retrieveFromCache) {
4736                    Object[] finderArgs = new Object[] {
4737                                    userId, classNameId, classPK, type, receiverUserId
4738                            };
4739    
4740                    Object result = null;
4741    
4742                    if (retrieveFromCache) {
4743                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
4744                                            finderArgs, this);
4745                    }
4746    
4747                    if (result instanceof SocialRequest) {
4748                            SocialRequest socialRequest = (SocialRequest)result;
4749    
4750                            if ((userId != socialRequest.getUserId()) ||
4751                                            (classNameId != socialRequest.getClassNameId()) ||
4752                                            (classPK != socialRequest.getClassPK()) ||
4753                                            (type != socialRequest.getType()) ||
4754                                            (receiverUserId != socialRequest.getReceiverUserId())) {
4755                                    result = null;
4756                            }
4757                    }
4758    
4759                    if (result == null) {
4760                            StringBundler query = new StringBundler(7);
4761    
4762                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
4763    
4764                            query.append(_FINDER_COLUMN_U_C_C_T_R_USERID_2);
4765    
4766                            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2);
4767    
4768                            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSPK_2);
4769    
4770                            query.append(_FINDER_COLUMN_U_C_C_T_R_TYPE_2);
4771    
4772                            query.append(_FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2);
4773    
4774                            String sql = query.toString();
4775    
4776                            Session session = null;
4777    
4778                            try {
4779                                    session = openSession();
4780    
4781                                    Query q = session.createQuery(sql);
4782    
4783                                    QueryPos qPos = QueryPos.getInstance(q);
4784    
4785                                    qPos.add(userId);
4786    
4787                                    qPos.add(classNameId);
4788    
4789                                    qPos.add(classPK);
4790    
4791                                    qPos.add(type);
4792    
4793                                    qPos.add(receiverUserId);
4794    
4795                                    List<SocialRequest> list = q.list();
4796    
4797                                    if (list.isEmpty()) {
4798                                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
4799                                                    finderArgs, list);
4800                                    }
4801                                    else {
4802                                            SocialRequest socialRequest = list.get(0);
4803    
4804                                            result = socialRequest;
4805    
4806                                            cacheResult(socialRequest);
4807    
4808                                            if ((socialRequest.getUserId() != userId) ||
4809                                                            (socialRequest.getClassNameId() != classNameId) ||
4810                                                            (socialRequest.getClassPK() != classPK) ||
4811                                                            (socialRequest.getType() != type) ||
4812                                                            (socialRequest.getReceiverUserId() != receiverUserId)) {
4813                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
4814                                                            finderArgs, socialRequest);
4815                                            }
4816                                    }
4817                            }
4818                            catch (Exception e) {
4819                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
4820                                            finderArgs);
4821    
4822                                    throw processException(e);
4823                            }
4824                            finally {
4825                                    closeSession(session);
4826                            }
4827                    }
4828    
4829                    if (result instanceof List<?>) {
4830                            return null;
4831                    }
4832                    else {
4833                            return (SocialRequest)result;
4834                    }
4835            }
4836    
4837            /**
4838             * Removes the social request where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; from the database.
4839             *
4840             * @param userId the user ID
4841             * @param classNameId the class name ID
4842             * @param classPK the class p k
4843             * @param type the type
4844             * @param receiverUserId the receiver user ID
4845             * @return the social request that was removed
4846             */
4847            @Override
4848            public SocialRequest removeByU_C_C_T_R(long userId, long classNameId,
4849                    long classPK, int type, long receiverUserId)
4850                    throws NoSuchRequestException {
4851                    SocialRequest socialRequest = findByU_C_C_T_R(userId, classNameId,
4852                                    classPK, type, receiverUserId);
4853    
4854                    return remove(socialRequest);
4855            }
4856    
4857            /**
4858             * Returns the number of social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63;.
4859             *
4860             * @param userId the user ID
4861             * @param classNameId the class name ID
4862             * @param classPK the class p k
4863             * @param type the type
4864             * @param receiverUserId the receiver user ID
4865             * @return the number of matching social requests
4866             */
4867            @Override
4868            public int countByU_C_C_T_R(long userId, long classNameId, long classPK,
4869                    int type, long receiverUserId) {
4870                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_T_R;
4871    
4872                    Object[] finderArgs = new Object[] {
4873                                    userId, classNameId, classPK, type, receiverUserId
4874                            };
4875    
4876                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4877    
4878                    if (count == null) {
4879                            StringBundler query = new StringBundler(6);
4880    
4881                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
4882    
4883                            query.append(_FINDER_COLUMN_U_C_C_T_R_USERID_2);
4884    
4885                            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2);
4886    
4887                            query.append(_FINDER_COLUMN_U_C_C_T_R_CLASSPK_2);
4888    
4889                            query.append(_FINDER_COLUMN_U_C_C_T_R_TYPE_2);
4890    
4891                            query.append(_FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2);
4892    
4893                            String sql = query.toString();
4894    
4895                            Session session = null;
4896    
4897                            try {
4898                                    session = openSession();
4899    
4900                                    Query q = session.createQuery(sql);
4901    
4902                                    QueryPos qPos = QueryPos.getInstance(q);
4903    
4904                                    qPos.add(userId);
4905    
4906                                    qPos.add(classNameId);
4907    
4908                                    qPos.add(classPK);
4909    
4910                                    qPos.add(type);
4911    
4912                                    qPos.add(receiverUserId);
4913    
4914                                    count = (Long)q.uniqueResult();
4915    
4916                                    finderCache.putResult(finderPath, finderArgs, count);
4917                            }
4918                            catch (Exception e) {
4919                                    finderCache.removeResult(finderPath, finderArgs);
4920    
4921                                    throw processException(e);
4922                            }
4923                            finally {
4924                                    closeSession(session);
4925                            }
4926                    }
4927    
4928                    return count.intValue();
4929            }
4930    
4931            private static final String _FINDER_COLUMN_U_C_C_T_R_USERID_2 = "socialRequest.userId = ? AND ";
4932            private static final String _FINDER_COLUMN_U_C_C_T_R_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
4933            private static final String _FINDER_COLUMN_U_C_C_T_R_CLASSPK_2 = "socialRequest.classPK = ? AND ";
4934            private static final String _FINDER_COLUMN_U_C_C_T_R_TYPE_2 = "socialRequest.type = ? AND ";
4935            private static final String _FINDER_COLUMN_U_C_C_T_R_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ?";
4936            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_T_S =
4937                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4938                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
4939                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
4940                            "findByU_C_C_T_S",
4941                            new String[] {
4942                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4943                                    Integer.class.getName(), Integer.class.getName(),
4944                                    
4945                            Integer.class.getName(), Integer.class.getName(),
4946                                    OrderByComparator.class.getName()
4947                            });
4948            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S =
4949                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4950                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
4951                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
4952                            "findByU_C_C_T_S",
4953                            new String[] {
4954                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4955                                    Integer.class.getName(), Integer.class.getName()
4956                            },
4957                            SocialRequestModelImpl.USERID_COLUMN_BITMASK |
4958                            SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4959                            SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK |
4960                            SocialRequestModelImpl.TYPE_COLUMN_BITMASK |
4961                            SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
4962            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_T_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
4963                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
4964                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_T_S",
4965                            new String[] {
4966                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4967                                    Integer.class.getName(), Integer.class.getName()
4968                            });
4969    
4970            /**
4971             * Returns all the social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
4972             *
4973             * @param userId the user ID
4974             * @param classNameId the class name ID
4975             * @param classPK the class p k
4976             * @param type the type
4977             * @param status the status
4978             * @return the matching social requests
4979             */
4980            @Override
4981            public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
4982                    long classPK, int type, int status) {
4983                    return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
4984                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4985            }
4986    
4987            /**
4988             * Returns a range of all the social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
4989             *
4990             * <p>
4991             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4992             * </p>
4993             *
4994             * @param userId the user ID
4995             * @param classNameId the class name ID
4996             * @param classPK the class p k
4997             * @param type the type
4998             * @param status the status
4999             * @param start the lower bound of the range of social requests
5000             * @param end the upper bound of the range of social requests (not inclusive)
5001             * @return the range of matching social requests
5002             */
5003            @Override
5004            public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
5005                    long classPK, int type, int status, int start, int end) {
5006                    return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
5007                            start, end, null);
5008            }
5009    
5010            /**
5011             * Returns an ordered range of all the social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
5012             *
5013             * <p>
5014             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5015             * </p>
5016             *
5017             * @param userId the user ID
5018             * @param classNameId the class name ID
5019             * @param classPK the class p k
5020             * @param type the type
5021             * @param status the status
5022             * @param start the lower bound of the range of social requests
5023             * @param end the upper bound of the range of social requests (not inclusive)
5024             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5025             * @return the ordered range of matching social requests
5026             */
5027            @Override
5028            public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
5029                    long classPK, int type, int status, int start, int end,
5030                    OrderByComparator<SocialRequest> orderByComparator) {
5031                    return findByU_C_C_T_S(userId, classNameId, classPK, type, status,
5032                            start, end, orderByComparator, true);
5033            }
5034    
5035            /**
5036             * Returns an ordered range of all the social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
5037             *
5038             * <p>
5039             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5040             * </p>
5041             *
5042             * @param userId the user ID
5043             * @param classNameId the class name ID
5044             * @param classPK the class p k
5045             * @param type the type
5046             * @param status the status
5047             * @param start the lower bound of the range of social requests
5048             * @param end the upper bound of the range of social requests (not inclusive)
5049             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5050             * @param retrieveFromCache whether to retrieve from the finder cache
5051             * @return the ordered range of matching social requests
5052             */
5053            @Override
5054            public List<SocialRequest> findByU_C_C_T_S(long userId, long classNameId,
5055                    long classPK, int type, int status, int start, int end,
5056                    OrderByComparator<SocialRequest> orderByComparator,
5057                    boolean retrieveFromCache) {
5058                    boolean pagination = true;
5059                    FinderPath finderPath = null;
5060                    Object[] finderArgs = null;
5061    
5062                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5063                                    (orderByComparator == null)) {
5064                            pagination = false;
5065                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S;
5066                            finderArgs = new Object[] { userId, classNameId, classPK, type, status };
5067                    }
5068                    else {
5069                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_T_S;
5070                            finderArgs = new Object[] {
5071                                            userId, classNameId, classPK, type, status,
5072                                            
5073                                            start, end, orderByComparator
5074                                    };
5075                    }
5076    
5077                    List<SocialRequest> list = null;
5078    
5079                    if (retrieveFromCache) {
5080                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
5081                                            finderArgs, this);
5082    
5083                            if ((list != null) && !list.isEmpty()) {
5084                                    for (SocialRequest socialRequest : list) {
5085                                            if ((userId != socialRequest.getUserId()) ||
5086                                                            (classNameId != socialRequest.getClassNameId()) ||
5087                                                            (classPK != socialRequest.getClassPK()) ||
5088                                                            (type != socialRequest.getType()) ||
5089                                                            (status != socialRequest.getStatus())) {
5090                                                    list = null;
5091    
5092                                                    break;
5093                                            }
5094                                    }
5095                            }
5096                    }
5097    
5098                    if (list == null) {
5099                            StringBundler query = null;
5100    
5101                            if (orderByComparator != null) {
5102                                    query = new StringBundler(7 +
5103                                                    (orderByComparator.getOrderByFields().length * 2));
5104                            }
5105                            else {
5106                                    query = new StringBundler(7);
5107                            }
5108    
5109                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
5110    
5111                            query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
5112    
5113                            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
5114    
5115                            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
5116    
5117                            query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
5118    
5119                            query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
5120    
5121                            if (orderByComparator != null) {
5122                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5123                                            orderByComparator);
5124                            }
5125                            else
5126                             if (pagination) {
5127                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
5128                            }
5129    
5130                            String sql = query.toString();
5131    
5132                            Session session = null;
5133    
5134                            try {
5135                                    session = openSession();
5136    
5137                                    Query q = session.createQuery(sql);
5138    
5139                                    QueryPos qPos = QueryPos.getInstance(q);
5140    
5141                                    qPos.add(userId);
5142    
5143                                    qPos.add(classNameId);
5144    
5145                                    qPos.add(classPK);
5146    
5147                                    qPos.add(type);
5148    
5149                                    qPos.add(status);
5150    
5151                                    if (!pagination) {
5152                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
5153                                                            start, end, false);
5154    
5155                                            Collections.sort(list);
5156    
5157                                            list = Collections.unmodifiableList(list);
5158                                    }
5159                                    else {
5160                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
5161                                                            start, end);
5162                                    }
5163    
5164                                    cacheResult(list);
5165    
5166                                    finderCache.putResult(finderPath, finderArgs, list);
5167                            }
5168                            catch (Exception e) {
5169                                    finderCache.removeResult(finderPath, finderArgs);
5170    
5171                                    throw processException(e);
5172                            }
5173                            finally {
5174                                    closeSession(session);
5175                            }
5176                    }
5177    
5178                    return list;
5179            }
5180    
5181            /**
5182             * Returns the first social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
5183             *
5184             * @param userId the user ID
5185             * @param classNameId the class name ID
5186             * @param classPK the class p k
5187             * @param type the type
5188             * @param status the status
5189             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5190             * @return the first matching social request
5191             * @throws NoSuchRequestException if a matching social request could not be found
5192             */
5193            @Override
5194            public SocialRequest findByU_C_C_T_S_First(long userId, long classNameId,
5195                    long classPK, int type, int status,
5196                    OrderByComparator<SocialRequest> orderByComparator)
5197                    throws NoSuchRequestException {
5198                    SocialRequest socialRequest = fetchByU_C_C_T_S_First(userId,
5199                                    classNameId, classPK, type, status, orderByComparator);
5200    
5201                    if (socialRequest != null) {
5202                            return socialRequest;
5203                    }
5204    
5205                    StringBundler msg = new StringBundler(12);
5206    
5207                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5208    
5209                    msg.append("userId=");
5210                    msg.append(userId);
5211    
5212                    msg.append(", classNameId=");
5213                    msg.append(classNameId);
5214    
5215                    msg.append(", classPK=");
5216                    msg.append(classPK);
5217    
5218                    msg.append(", type=");
5219                    msg.append(type);
5220    
5221                    msg.append(", status=");
5222                    msg.append(status);
5223    
5224                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5225    
5226                    throw new NoSuchRequestException(msg.toString());
5227            }
5228    
5229            /**
5230             * Returns the first social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
5231             *
5232             * @param userId the user ID
5233             * @param classNameId the class name ID
5234             * @param classPK the class p k
5235             * @param type the type
5236             * @param status the status
5237             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5238             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
5239             */
5240            @Override
5241            public SocialRequest fetchByU_C_C_T_S_First(long userId, long classNameId,
5242                    long classPK, int type, int status,
5243                    OrderByComparator<SocialRequest> orderByComparator) {
5244                    List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
5245                                    classPK, type, status, 0, 1, orderByComparator);
5246    
5247                    if (!list.isEmpty()) {
5248                            return list.get(0);
5249                    }
5250    
5251                    return null;
5252            }
5253    
5254            /**
5255             * Returns the last social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
5256             *
5257             * @param userId the user ID
5258             * @param classNameId the class name ID
5259             * @param classPK the class p k
5260             * @param type the type
5261             * @param status the status
5262             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5263             * @return the last matching social request
5264             * @throws NoSuchRequestException if a matching social request could not be found
5265             */
5266            @Override
5267            public SocialRequest findByU_C_C_T_S_Last(long userId, long classNameId,
5268                    long classPK, int type, int status,
5269                    OrderByComparator<SocialRequest> orderByComparator)
5270                    throws NoSuchRequestException {
5271                    SocialRequest socialRequest = fetchByU_C_C_T_S_Last(userId,
5272                                    classNameId, classPK, type, status, orderByComparator);
5273    
5274                    if (socialRequest != null) {
5275                            return socialRequest;
5276                    }
5277    
5278                    StringBundler msg = new StringBundler(12);
5279    
5280                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5281    
5282                    msg.append("userId=");
5283                    msg.append(userId);
5284    
5285                    msg.append(", classNameId=");
5286                    msg.append(classNameId);
5287    
5288                    msg.append(", classPK=");
5289                    msg.append(classPK);
5290    
5291                    msg.append(", type=");
5292                    msg.append(type);
5293    
5294                    msg.append(", status=");
5295                    msg.append(status);
5296    
5297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5298    
5299                    throw new NoSuchRequestException(msg.toString());
5300            }
5301    
5302            /**
5303             * Returns the last social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
5304             *
5305             * @param userId the user ID
5306             * @param classNameId the class name ID
5307             * @param classPK the class p k
5308             * @param type the type
5309             * @param status the status
5310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5311             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
5312             */
5313            @Override
5314            public SocialRequest fetchByU_C_C_T_S_Last(long userId, long classNameId,
5315                    long classPK, int type, int status,
5316                    OrderByComparator<SocialRequest> orderByComparator) {
5317                    int count = countByU_C_C_T_S(userId, classNameId, classPK, type, status);
5318    
5319                    if (count == 0) {
5320                            return null;
5321                    }
5322    
5323                    List<SocialRequest> list = findByU_C_C_T_S(userId, classNameId,
5324                                    classPK, type, status, count - 1, count, orderByComparator);
5325    
5326                    if (!list.isEmpty()) {
5327                            return list.get(0);
5328                    }
5329    
5330                    return null;
5331            }
5332    
5333            /**
5334             * Returns the social requests before and after the current social request in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
5335             *
5336             * @param requestId the primary key of the current social request
5337             * @param userId the user ID
5338             * @param classNameId the class name ID
5339             * @param classPK the class p k
5340             * @param type the type
5341             * @param status the status
5342             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5343             * @return the previous, current, and next social request
5344             * @throws NoSuchRequestException if a social request with the primary key could not be found
5345             */
5346            @Override
5347            public SocialRequest[] findByU_C_C_T_S_PrevAndNext(long requestId,
5348                    long userId, long classNameId, long classPK, int type, int status,
5349                    OrderByComparator<SocialRequest> orderByComparator)
5350                    throws NoSuchRequestException {
5351                    SocialRequest socialRequest = findByPrimaryKey(requestId);
5352    
5353                    Session session = null;
5354    
5355                    try {
5356                            session = openSession();
5357    
5358                            SocialRequest[] array = new SocialRequestImpl[3];
5359    
5360                            array[0] = getByU_C_C_T_S_PrevAndNext(session, socialRequest,
5361                                            userId, classNameId, classPK, type, status,
5362                                            orderByComparator, true);
5363    
5364                            array[1] = socialRequest;
5365    
5366                            array[2] = getByU_C_C_T_S_PrevAndNext(session, socialRequest,
5367                                            userId, classNameId, classPK, type, status,
5368                                            orderByComparator, false);
5369    
5370                            return array;
5371                    }
5372                    catch (Exception e) {
5373                            throw processException(e);
5374                    }
5375                    finally {
5376                            closeSession(session);
5377                    }
5378            }
5379    
5380            protected SocialRequest getByU_C_C_T_S_PrevAndNext(Session session,
5381                    SocialRequest socialRequest, long userId, long classNameId,
5382                    long classPK, int type, int status,
5383                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
5384                    StringBundler query = null;
5385    
5386                    if (orderByComparator != null) {
5387                            query = new StringBundler(8 +
5388                                            (orderByComparator.getOrderByConditionFields().length * 3) +
5389                                            (orderByComparator.getOrderByFields().length * 3));
5390                    }
5391                    else {
5392                            query = new StringBundler(7);
5393                    }
5394    
5395                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
5396    
5397                    query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
5398    
5399                    query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
5400    
5401                    query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
5402    
5403                    query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
5404    
5405                    query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
5406    
5407                    if (orderByComparator != null) {
5408                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5409    
5410                            if (orderByConditionFields.length > 0) {
5411                                    query.append(WHERE_AND);
5412                            }
5413    
5414                            for (int i = 0; i < orderByConditionFields.length; i++) {
5415                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5416                                    query.append(orderByConditionFields[i]);
5417    
5418                                    if ((i + 1) < orderByConditionFields.length) {
5419                                            if (orderByComparator.isAscending() ^ previous) {
5420                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5421                                            }
5422                                            else {
5423                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5424                                            }
5425                                    }
5426                                    else {
5427                                            if (orderByComparator.isAscending() ^ previous) {
5428                                                    query.append(WHERE_GREATER_THAN);
5429                                            }
5430                                            else {
5431                                                    query.append(WHERE_LESSER_THAN);
5432                                            }
5433                                    }
5434                            }
5435    
5436                            query.append(ORDER_BY_CLAUSE);
5437    
5438                            String[] orderByFields = orderByComparator.getOrderByFields();
5439    
5440                            for (int i = 0; i < orderByFields.length; i++) {
5441                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5442                                    query.append(orderByFields[i]);
5443    
5444                                    if ((i + 1) < orderByFields.length) {
5445                                            if (orderByComparator.isAscending() ^ previous) {
5446                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5447                                            }
5448                                            else {
5449                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5450                                            }
5451                                    }
5452                                    else {
5453                                            if (orderByComparator.isAscending() ^ previous) {
5454                                                    query.append(ORDER_BY_ASC);
5455                                            }
5456                                            else {
5457                                                    query.append(ORDER_BY_DESC);
5458                                            }
5459                                    }
5460                            }
5461                    }
5462                    else {
5463                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
5464                    }
5465    
5466                    String sql = query.toString();
5467    
5468                    Query q = session.createQuery(sql);
5469    
5470                    q.setFirstResult(0);
5471                    q.setMaxResults(2);
5472    
5473                    QueryPos qPos = QueryPos.getInstance(q);
5474    
5475                    qPos.add(userId);
5476    
5477                    qPos.add(classNameId);
5478    
5479                    qPos.add(classPK);
5480    
5481                    qPos.add(type);
5482    
5483                    qPos.add(status);
5484    
5485                    if (orderByComparator != null) {
5486                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
5487    
5488                            for (Object value : values) {
5489                                    qPos.add(value);
5490                            }
5491                    }
5492    
5493                    List<SocialRequest> list = q.list();
5494    
5495                    if (list.size() == 2) {
5496                            return list.get(1);
5497                    }
5498                    else {
5499                            return null;
5500                    }
5501            }
5502    
5503            /**
5504             * Removes all the social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63; from the database.
5505             *
5506             * @param userId the user ID
5507             * @param classNameId the class name ID
5508             * @param classPK the class p k
5509             * @param type the type
5510             * @param status the status
5511             */
5512            @Override
5513            public void removeByU_C_C_T_S(long userId, long classNameId, long classPK,
5514                    int type, int status) {
5515                    for (SocialRequest socialRequest : findByU_C_C_T_S(userId, classNameId,
5516                                    classPK, type, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5517                                    null)) {
5518                            remove(socialRequest);
5519                    }
5520            }
5521    
5522            /**
5523             * Returns the number of social requests where userId = &#63; and classNameId = &#63; and classPK = &#63; and type = &#63; and status = &#63;.
5524             *
5525             * @param userId the user ID
5526             * @param classNameId the class name ID
5527             * @param classPK the class p k
5528             * @param type the type
5529             * @param status the status
5530             * @return the number of matching social requests
5531             */
5532            @Override
5533            public int countByU_C_C_T_S(long userId, long classNameId, long classPK,
5534                    int type, int status) {
5535                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_T_S;
5536    
5537                    Object[] finderArgs = new Object[] {
5538                                    userId, classNameId, classPK, type, status
5539                            };
5540    
5541                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5542    
5543                    if (count == null) {
5544                            StringBundler query = new StringBundler(6);
5545    
5546                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
5547    
5548                            query.append(_FINDER_COLUMN_U_C_C_T_S_USERID_2);
5549    
5550                            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2);
5551    
5552                            query.append(_FINDER_COLUMN_U_C_C_T_S_CLASSPK_2);
5553    
5554                            query.append(_FINDER_COLUMN_U_C_C_T_S_TYPE_2);
5555    
5556                            query.append(_FINDER_COLUMN_U_C_C_T_S_STATUS_2);
5557    
5558                            String sql = query.toString();
5559    
5560                            Session session = null;
5561    
5562                            try {
5563                                    session = openSession();
5564    
5565                                    Query q = session.createQuery(sql);
5566    
5567                                    QueryPos qPos = QueryPos.getInstance(q);
5568    
5569                                    qPos.add(userId);
5570    
5571                                    qPos.add(classNameId);
5572    
5573                                    qPos.add(classPK);
5574    
5575                                    qPos.add(type);
5576    
5577                                    qPos.add(status);
5578    
5579                                    count = (Long)q.uniqueResult();
5580    
5581                                    finderCache.putResult(finderPath, finderArgs, count);
5582                            }
5583                            catch (Exception e) {
5584                                    finderCache.removeResult(finderPath, finderArgs);
5585    
5586                                    throw processException(e);
5587                            }
5588                            finally {
5589                                    closeSession(session);
5590                            }
5591                    }
5592    
5593                    return count.intValue();
5594            }
5595    
5596            private static final String _FINDER_COLUMN_U_C_C_T_S_USERID_2 = "socialRequest.userId = ? AND ";
5597            private static final String _FINDER_COLUMN_U_C_C_T_S_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
5598            private static final String _FINDER_COLUMN_U_C_C_T_S_CLASSPK_2 = "socialRequest.classPK = ? AND ";
5599            private static final String _FINDER_COLUMN_U_C_C_T_S_TYPE_2 = "socialRequest.type = ? AND ";
5600            private static final String _FINDER_COLUMN_U_C_C_T_S_STATUS_2 = "socialRequest.status = ?";
5601            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T_R_S =
5602                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
5603                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
5604                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
5605                            "findByC_C_T_R_S",
5606                            new String[] {
5607                                    Long.class.getName(), Long.class.getName(),
5608                                    Integer.class.getName(), Long.class.getName(),
5609                                    Integer.class.getName(),
5610                                    
5611                            Integer.class.getName(), Integer.class.getName(),
5612                                    OrderByComparator.class.getName()
5613                            });
5614            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S =
5615                    new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
5616                            SocialRequestModelImpl.FINDER_CACHE_ENABLED,
5617                            SocialRequestImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
5618                            "findByC_C_T_R_S",
5619                            new String[] {
5620                                    Long.class.getName(), Long.class.getName(),
5621                                    Integer.class.getName(), Long.class.getName(),
5622                                    Integer.class.getName()
5623                            },
5624                            SocialRequestModelImpl.CLASSNAMEID_COLUMN_BITMASK |
5625                            SocialRequestModelImpl.CLASSPK_COLUMN_BITMASK |
5626                            SocialRequestModelImpl.TYPE_COLUMN_BITMASK |
5627                            SocialRequestModelImpl.RECEIVERUSERID_COLUMN_BITMASK |
5628                            SocialRequestModelImpl.STATUS_COLUMN_BITMASK);
5629            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_T_R_S = new FinderPath(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
5630                            SocialRequestModelImpl.FINDER_CACHE_ENABLED, Long.class,
5631                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_T_R_S",
5632                            new String[] {
5633                                    Long.class.getName(), Long.class.getName(),
5634                                    Integer.class.getName(), Long.class.getName(),
5635                                    Integer.class.getName()
5636                            });
5637    
5638            /**
5639             * Returns all the social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
5640             *
5641             * @param classNameId the class name ID
5642             * @param classPK the class p k
5643             * @param type the type
5644             * @param receiverUserId the receiver user ID
5645             * @param status the status
5646             * @return the matching social requests
5647             */
5648            @Override
5649            public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
5650                    int type, long receiverUserId, int status) {
5651                    return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
5652                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5653            }
5654    
5655            /**
5656             * Returns a range of all the social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
5657             *
5658             * <p>
5659             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5660             * </p>
5661             *
5662             * @param classNameId the class name ID
5663             * @param classPK the class p k
5664             * @param type the type
5665             * @param receiverUserId the receiver user ID
5666             * @param status the status
5667             * @param start the lower bound of the range of social requests
5668             * @param end the upper bound of the range of social requests (not inclusive)
5669             * @return the range of matching social requests
5670             */
5671            @Override
5672            public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
5673                    int type, long receiverUserId, int status, int start, int end) {
5674                    return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
5675                            status, start, end, null);
5676            }
5677    
5678            /**
5679             * Returns an ordered range of all the social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
5680             *
5681             * <p>
5682             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5683             * </p>
5684             *
5685             * @param classNameId the class name ID
5686             * @param classPK the class p k
5687             * @param type the type
5688             * @param receiverUserId the receiver user ID
5689             * @param status the status
5690             * @param start the lower bound of the range of social requests
5691             * @param end the upper bound of the range of social requests (not inclusive)
5692             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5693             * @return the ordered range of matching social requests
5694             */
5695            @Override
5696            public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
5697                    int type, long receiverUserId, int status, int start, int end,
5698                    OrderByComparator<SocialRequest> orderByComparator) {
5699                    return findByC_C_T_R_S(classNameId, classPK, type, receiverUserId,
5700                            status, start, end, orderByComparator, true);
5701            }
5702    
5703            /**
5704             * Returns an ordered range of all the social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
5705             *
5706             * <p>
5707             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5708             * </p>
5709             *
5710             * @param classNameId the class name ID
5711             * @param classPK the class p k
5712             * @param type the type
5713             * @param receiverUserId the receiver user ID
5714             * @param status the status
5715             * @param start the lower bound of the range of social requests
5716             * @param end the upper bound of the range of social requests (not inclusive)
5717             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5718             * @param retrieveFromCache whether to retrieve from the finder cache
5719             * @return the ordered range of matching social requests
5720             */
5721            @Override
5722            public List<SocialRequest> findByC_C_T_R_S(long classNameId, long classPK,
5723                    int type, long receiverUserId, int status, int start, int end,
5724                    OrderByComparator<SocialRequest> orderByComparator,
5725                    boolean retrieveFromCache) {
5726                    boolean pagination = true;
5727                    FinderPath finderPath = null;
5728                    Object[] finderArgs = null;
5729    
5730                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5731                                    (orderByComparator == null)) {
5732                            pagination = false;
5733                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S;
5734                            finderArgs = new Object[] {
5735                                            classNameId, classPK, type, receiverUserId, status
5736                                    };
5737                    }
5738                    else {
5739                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_T_R_S;
5740                            finderArgs = new Object[] {
5741                                            classNameId, classPK, type, receiverUserId, status,
5742                                            
5743                                            start, end, orderByComparator
5744                                    };
5745                    }
5746    
5747                    List<SocialRequest> list = null;
5748    
5749                    if (retrieveFromCache) {
5750                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
5751                                            finderArgs, this);
5752    
5753                            if ((list != null) && !list.isEmpty()) {
5754                                    for (SocialRequest socialRequest : list) {
5755                                            if ((classNameId != socialRequest.getClassNameId()) ||
5756                                                            (classPK != socialRequest.getClassPK()) ||
5757                                                            (type != socialRequest.getType()) ||
5758                                                            (receiverUserId != socialRequest.getReceiverUserId()) ||
5759                                                            (status != socialRequest.getStatus())) {
5760                                                    list = null;
5761    
5762                                                    break;
5763                                            }
5764                                    }
5765                            }
5766                    }
5767    
5768                    if (list == null) {
5769                            StringBundler query = null;
5770    
5771                            if (orderByComparator != null) {
5772                                    query = new StringBundler(7 +
5773                                                    (orderByComparator.getOrderByFields().length * 2));
5774                            }
5775                            else {
5776                                    query = new StringBundler(7);
5777                            }
5778    
5779                            query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
5780    
5781                            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
5782    
5783                            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
5784    
5785                            query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
5786    
5787                            query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
5788    
5789                            query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
5790    
5791                            if (orderByComparator != null) {
5792                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5793                                            orderByComparator);
5794                            }
5795                            else
5796                             if (pagination) {
5797                                    query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
5798                            }
5799    
5800                            String sql = query.toString();
5801    
5802                            Session session = null;
5803    
5804                            try {
5805                                    session = openSession();
5806    
5807                                    Query q = session.createQuery(sql);
5808    
5809                                    QueryPos qPos = QueryPos.getInstance(q);
5810    
5811                                    qPos.add(classNameId);
5812    
5813                                    qPos.add(classPK);
5814    
5815                                    qPos.add(type);
5816    
5817                                    qPos.add(receiverUserId);
5818    
5819                                    qPos.add(status);
5820    
5821                                    if (!pagination) {
5822                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
5823                                                            start, end, false);
5824    
5825                                            Collections.sort(list);
5826    
5827                                            list = Collections.unmodifiableList(list);
5828                                    }
5829                                    else {
5830                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
5831                                                            start, end);
5832                                    }
5833    
5834                                    cacheResult(list);
5835    
5836                                    finderCache.putResult(finderPath, finderArgs, list);
5837                            }
5838                            catch (Exception e) {
5839                                    finderCache.removeResult(finderPath, finderArgs);
5840    
5841                                    throw processException(e);
5842                            }
5843                            finally {
5844                                    closeSession(session);
5845                            }
5846                    }
5847    
5848                    return list;
5849            }
5850    
5851            /**
5852             * Returns the first social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
5853             *
5854             * @param classNameId the class name ID
5855             * @param classPK the class p k
5856             * @param type the type
5857             * @param receiverUserId the receiver user ID
5858             * @param status the status
5859             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5860             * @return the first matching social request
5861             * @throws NoSuchRequestException if a matching social request could not be found
5862             */
5863            @Override
5864            public SocialRequest findByC_C_T_R_S_First(long classNameId, long classPK,
5865                    int type, long receiverUserId, int status,
5866                    OrderByComparator<SocialRequest> orderByComparator)
5867                    throws NoSuchRequestException {
5868                    SocialRequest socialRequest = fetchByC_C_T_R_S_First(classNameId,
5869                                    classPK, type, receiverUserId, status, orderByComparator);
5870    
5871                    if (socialRequest != null) {
5872                            return socialRequest;
5873                    }
5874    
5875                    StringBundler msg = new StringBundler(12);
5876    
5877                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5878    
5879                    msg.append("classNameId=");
5880                    msg.append(classNameId);
5881    
5882                    msg.append(", classPK=");
5883                    msg.append(classPK);
5884    
5885                    msg.append(", type=");
5886                    msg.append(type);
5887    
5888                    msg.append(", receiverUserId=");
5889                    msg.append(receiverUserId);
5890    
5891                    msg.append(", status=");
5892                    msg.append(status);
5893    
5894                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5895    
5896                    throw new NoSuchRequestException(msg.toString());
5897            }
5898    
5899            /**
5900             * Returns the first social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
5901             *
5902             * @param classNameId the class name ID
5903             * @param classPK the class p k
5904             * @param type the type
5905             * @param receiverUserId the receiver user ID
5906             * @param status the status
5907             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5908             * @return the first matching social request, or <code>null</code> if a matching social request could not be found
5909             */
5910            @Override
5911            public SocialRequest fetchByC_C_T_R_S_First(long classNameId, long classPK,
5912                    int type, long receiverUserId, int status,
5913                    OrderByComparator<SocialRequest> orderByComparator) {
5914                    List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
5915                                    receiverUserId, status, 0, 1, orderByComparator);
5916    
5917                    if (!list.isEmpty()) {
5918                            return list.get(0);
5919                    }
5920    
5921                    return null;
5922            }
5923    
5924            /**
5925             * Returns the last social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
5926             *
5927             * @param classNameId the class name ID
5928             * @param classPK the class p k
5929             * @param type the type
5930             * @param receiverUserId the receiver user ID
5931             * @param status the status
5932             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5933             * @return the last matching social request
5934             * @throws NoSuchRequestException if a matching social request could not be found
5935             */
5936            @Override
5937            public SocialRequest findByC_C_T_R_S_Last(long classNameId, long classPK,
5938                    int type, long receiverUserId, int status,
5939                    OrderByComparator<SocialRequest> orderByComparator)
5940                    throws NoSuchRequestException {
5941                    SocialRequest socialRequest = fetchByC_C_T_R_S_Last(classNameId,
5942                                    classPK, type, receiverUserId, status, orderByComparator);
5943    
5944                    if (socialRequest != null) {
5945                            return socialRequest;
5946                    }
5947    
5948                    StringBundler msg = new StringBundler(12);
5949    
5950                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5951    
5952                    msg.append("classNameId=");
5953                    msg.append(classNameId);
5954    
5955                    msg.append(", classPK=");
5956                    msg.append(classPK);
5957    
5958                    msg.append(", type=");
5959                    msg.append(type);
5960    
5961                    msg.append(", receiverUserId=");
5962                    msg.append(receiverUserId);
5963    
5964                    msg.append(", status=");
5965                    msg.append(status);
5966    
5967                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5968    
5969                    throw new NoSuchRequestException(msg.toString());
5970            }
5971    
5972            /**
5973             * Returns the last social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
5974             *
5975             * @param classNameId the class name ID
5976             * @param classPK the class p k
5977             * @param type the type
5978             * @param receiverUserId the receiver user ID
5979             * @param status the status
5980             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5981             * @return the last matching social request, or <code>null</code> if a matching social request could not be found
5982             */
5983            @Override
5984            public SocialRequest fetchByC_C_T_R_S_Last(long classNameId, long classPK,
5985                    int type, long receiverUserId, int status,
5986                    OrderByComparator<SocialRequest> orderByComparator) {
5987                    int count = countByC_C_T_R_S(classNameId, classPK, type,
5988                                    receiverUserId, status);
5989    
5990                    if (count == 0) {
5991                            return null;
5992                    }
5993    
5994                    List<SocialRequest> list = findByC_C_T_R_S(classNameId, classPK, type,
5995                                    receiverUserId, status, count - 1, count, orderByComparator);
5996    
5997                    if (!list.isEmpty()) {
5998                            return list.get(0);
5999                    }
6000    
6001                    return null;
6002            }
6003    
6004            /**
6005             * Returns the social requests before and after the current social request in the ordered set where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
6006             *
6007             * @param requestId the primary key of the current social request
6008             * @param classNameId the class name ID
6009             * @param classPK the class p k
6010             * @param type the type
6011             * @param receiverUserId the receiver user ID
6012             * @param status the status
6013             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6014             * @return the previous, current, and next social request
6015             * @throws NoSuchRequestException if a social request with the primary key could not be found
6016             */
6017            @Override
6018            public SocialRequest[] findByC_C_T_R_S_PrevAndNext(long requestId,
6019                    long classNameId, long classPK, int type, long receiverUserId,
6020                    int status, OrderByComparator<SocialRequest> orderByComparator)
6021                    throws NoSuchRequestException {
6022                    SocialRequest socialRequest = findByPrimaryKey(requestId);
6023    
6024                    Session session = null;
6025    
6026                    try {
6027                            session = openSession();
6028    
6029                            SocialRequest[] array = new SocialRequestImpl[3];
6030    
6031                            array[0] = getByC_C_T_R_S_PrevAndNext(session, socialRequest,
6032                                            classNameId, classPK, type, receiverUserId, status,
6033                                            orderByComparator, true);
6034    
6035                            array[1] = socialRequest;
6036    
6037                            array[2] = getByC_C_T_R_S_PrevAndNext(session, socialRequest,
6038                                            classNameId, classPK, type, receiverUserId, status,
6039                                            orderByComparator, false);
6040    
6041                            return array;
6042                    }
6043                    catch (Exception e) {
6044                            throw processException(e);
6045                    }
6046                    finally {
6047                            closeSession(session);
6048                    }
6049            }
6050    
6051            protected SocialRequest getByC_C_T_R_S_PrevAndNext(Session session,
6052                    SocialRequest socialRequest, long classNameId, long classPK, int type,
6053                    long receiverUserId, int status,
6054                    OrderByComparator<SocialRequest> orderByComparator, boolean previous) {
6055                    StringBundler query = null;
6056    
6057                    if (orderByComparator != null) {
6058                            query = new StringBundler(8 +
6059                                            (orderByComparator.getOrderByConditionFields().length * 3) +
6060                                            (orderByComparator.getOrderByFields().length * 3));
6061                    }
6062                    else {
6063                            query = new StringBundler(7);
6064                    }
6065    
6066                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE);
6067    
6068                    query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
6069    
6070                    query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
6071    
6072                    query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
6073    
6074                    query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
6075    
6076                    query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
6077    
6078                    if (orderByComparator != null) {
6079                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6080    
6081                            if (orderByConditionFields.length > 0) {
6082                                    query.append(WHERE_AND);
6083                            }
6084    
6085                            for (int i = 0; i < orderByConditionFields.length; i++) {
6086                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6087                                    query.append(orderByConditionFields[i]);
6088    
6089                                    if ((i + 1) < orderByConditionFields.length) {
6090                                            if (orderByComparator.isAscending() ^ previous) {
6091                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6092                                            }
6093                                            else {
6094                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6095                                            }
6096                                    }
6097                                    else {
6098                                            if (orderByComparator.isAscending() ^ previous) {
6099                                                    query.append(WHERE_GREATER_THAN);
6100                                            }
6101                                            else {
6102                                                    query.append(WHERE_LESSER_THAN);
6103                                            }
6104                                    }
6105                            }
6106    
6107                            query.append(ORDER_BY_CLAUSE);
6108    
6109                            String[] orderByFields = orderByComparator.getOrderByFields();
6110    
6111                            for (int i = 0; i < orderByFields.length; i++) {
6112                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6113                                    query.append(orderByFields[i]);
6114    
6115                                    if ((i + 1) < orderByFields.length) {
6116                                            if (orderByComparator.isAscending() ^ previous) {
6117                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6118                                            }
6119                                            else {
6120                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6121                                            }
6122                                    }
6123                                    else {
6124                                            if (orderByComparator.isAscending() ^ previous) {
6125                                                    query.append(ORDER_BY_ASC);
6126                                            }
6127                                            else {
6128                                                    query.append(ORDER_BY_DESC);
6129                                            }
6130                                    }
6131                            }
6132                    }
6133                    else {
6134                            query.append(SocialRequestModelImpl.ORDER_BY_JPQL);
6135                    }
6136    
6137                    String sql = query.toString();
6138    
6139                    Query q = session.createQuery(sql);
6140    
6141                    q.setFirstResult(0);
6142                    q.setMaxResults(2);
6143    
6144                    QueryPos qPos = QueryPos.getInstance(q);
6145    
6146                    qPos.add(classNameId);
6147    
6148                    qPos.add(classPK);
6149    
6150                    qPos.add(type);
6151    
6152                    qPos.add(receiverUserId);
6153    
6154                    qPos.add(status);
6155    
6156                    if (orderByComparator != null) {
6157                            Object[] values = orderByComparator.getOrderByConditionValues(socialRequest);
6158    
6159                            for (Object value : values) {
6160                                    qPos.add(value);
6161                            }
6162                    }
6163    
6164                    List<SocialRequest> list = q.list();
6165    
6166                    if (list.size() == 2) {
6167                            return list.get(1);
6168                    }
6169                    else {
6170                            return null;
6171                    }
6172            }
6173    
6174            /**
6175             * Removes all the social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63; from the database.
6176             *
6177             * @param classNameId the class name ID
6178             * @param classPK the class p k
6179             * @param type the type
6180             * @param receiverUserId the receiver user ID
6181             * @param status the status
6182             */
6183            @Override
6184            public void removeByC_C_T_R_S(long classNameId, long classPK, int type,
6185                    long receiverUserId, int status) {
6186                    for (SocialRequest socialRequest : findByC_C_T_R_S(classNameId,
6187                                    classPK, type, receiverUserId, status, QueryUtil.ALL_POS,
6188                                    QueryUtil.ALL_POS, null)) {
6189                            remove(socialRequest);
6190                    }
6191            }
6192    
6193            /**
6194             * Returns the number of social requests where classNameId = &#63; and classPK = &#63; and type = &#63; and receiverUserId = &#63; and status = &#63;.
6195             *
6196             * @param classNameId the class name ID
6197             * @param classPK the class p k
6198             * @param type the type
6199             * @param receiverUserId the receiver user ID
6200             * @param status the status
6201             * @return the number of matching social requests
6202             */
6203            @Override
6204            public int countByC_C_T_R_S(long classNameId, long classPK, int type,
6205                    long receiverUserId, int status) {
6206                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_T_R_S;
6207    
6208                    Object[] finderArgs = new Object[] {
6209                                    classNameId, classPK, type, receiverUserId, status
6210                            };
6211    
6212                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6213    
6214                    if (count == null) {
6215                            StringBundler query = new StringBundler(6);
6216    
6217                            query.append(_SQL_COUNT_SOCIALREQUEST_WHERE);
6218    
6219                            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2);
6220    
6221                            query.append(_FINDER_COLUMN_C_C_T_R_S_CLASSPK_2);
6222    
6223                            query.append(_FINDER_COLUMN_C_C_T_R_S_TYPE_2);
6224    
6225                            query.append(_FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2);
6226    
6227                            query.append(_FINDER_COLUMN_C_C_T_R_S_STATUS_2);
6228    
6229                            String sql = query.toString();
6230    
6231                            Session session = null;
6232    
6233                            try {
6234                                    session = openSession();
6235    
6236                                    Query q = session.createQuery(sql);
6237    
6238                                    QueryPos qPos = QueryPos.getInstance(q);
6239    
6240                                    qPos.add(classNameId);
6241    
6242                                    qPos.add(classPK);
6243    
6244                                    qPos.add(type);
6245    
6246                                    qPos.add(receiverUserId);
6247    
6248                                    qPos.add(status);
6249    
6250                                    count = (Long)q.uniqueResult();
6251    
6252                                    finderCache.putResult(finderPath, finderArgs, count);
6253                            }
6254                            catch (Exception e) {
6255                                    finderCache.removeResult(finderPath, finderArgs);
6256    
6257                                    throw processException(e);
6258                            }
6259                            finally {
6260                                    closeSession(session);
6261                            }
6262                    }
6263    
6264                    return count.intValue();
6265            }
6266    
6267            private static final String _FINDER_COLUMN_C_C_T_R_S_CLASSNAMEID_2 = "socialRequest.classNameId = ? AND ";
6268            private static final String _FINDER_COLUMN_C_C_T_R_S_CLASSPK_2 = "socialRequest.classPK = ? AND ";
6269            private static final String _FINDER_COLUMN_C_C_T_R_S_TYPE_2 = "socialRequest.type = ? AND ";
6270            private static final String _FINDER_COLUMN_C_C_T_R_S_RECEIVERUSERID_2 = "socialRequest.receiverUserId = ? AND ";
6271            private static final String _FINDER_COLUMN_C_C_T_R_S_STATUS_2 = "socialRequest.status = ?";
6272    
6273            public SocialRequestPersistenceImpl() {
6274                    setModelClass(SocialRequest.class);
6275            }
6276    
6277            /**
6278             * Caches the social request in the entity cache if it is enabled.
6279             *
6280             * @param socialRequest the social request
6281             */
6282            @Override
6283            public void cacheResult(SocialRequest socialRequest) {
6284                    entityCache.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6285                            SocialRequestImpl.class, socialRequest.getPrimaryKey(),
6286                            socialRequest);
6287    
6288                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
6289                            new Object[] { socialRequest.getUuid(), socialRequest.getGroupId() },
6290                            socialRequest);
6291    
6292                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R,
6293                            new Object[] {
6294                                    socialRequest.getUserId(), socialRequest.getClassNameId(),
6295                                    socialRequest.getClassPK(), socialRequest.getType(),
6296                                    socialRequest.getReceiverUserId()
6297                            }, socialRequest);
6298    
6299                    socialRequest.resetOriginalValues();
6300            }
6301    
6302            /**
6303             * Caches the social requests in the entity cache if it is enabled.
6304             *
6305             * @param socialRequests the social requests
6306             */
6307            @Override
6308            public void cacheResult(List<SocialRequest> socialRequests) {
6309                    for (SocialRequest socialRequest : socialRequests) {
6310                            if (entityCache.getResult(
6311                                                    SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6312                                                    SocialRequestImpl.class, socialRequest.getPrimaryKey()) == null) {
6313                                    cacheResult(socialRequest);
6314                            }
6315                            else {
6316                                    socialRequest.resetOriginalValues();
6317                            }
6318                    }
6319            }
6320    
6321            /**
6322             * Clears the cache for all social requests.
6323             *
6324             * <p>
6325             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
6326             * </p>
6327             */
6328            @Override
6329            public void clearCache() {
6330                    entityCache.clearCache(SocialRequestImpl.class);
6331    
6332                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
6333                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6334                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6335            }
6336    
6337            /**
6338             * Clears the cache for the social request.
6339             *
6340             * <p>
6341             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
6342             * </p>
6343             */
6344            @Override
6345            public void clearCache(SocialRequest socialRequest) {
6346                    entityCache.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6347                            SocialRequestImpl.class, socialRequest.getPrimaryKey());
6348    
6349                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6350                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6351    
6352                    clearUniqueFindersCache((SocialRequestModelImpl)socialRequest);
6353            }
6354    
6355            @Override
6356            public void clearCache(List<SocialRequest> socialRequests) {
6357                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6358                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6359    
6360                    for (SocialRequest socialRequest : socialRequests) {
6361                            entityCache.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6362                                    SocialRequestImpl.class, socialRequest.getPrimaryKey());
6363    
6364                            clearUniqueFindersCache((SocialRequestModelImpl)socialRequest);
6365                    }
6366            }
6367    
6368            protected void cacheUniqueFindersCache(
6369                    SocialRequestModelImpl socialRequestModelImpl, boolean isNew) {
6370                    if (isNew) {
6371                            Object[] args = new Object[] {
6372                                            socialRequestModelImpl.getUuid(),
6373                                            socialRequestModelImpl.getGroupId()
6374                                    };
6375    
6376                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6377                                    Long.valueOf(1));
6378                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
6379                                    socialRequestModelImpl);
6380    
6381                            args = new Object[] {
6382                                            socialRequestModelImpl.getUserId(),
6383                                            socialRequestModelImpl.getClassNameId(),
6384                                            socialRequestModelImpl.getClassPK(),
6385                                            socialRequestModelImpl.getType(),
6386                                            socialRequestModelImpl.getReceiverUserId()
6387                                    };
6388    
6389                            finderCache.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args,
6390                                    Long.valueOf(1));
6391                            finderCache.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args,
6392                                    socialRequestModelImpl);
6393                    }
6394                    else {
6395                            if ((socialRequestModelImpl.getColumnBitmask() &
6396                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6397                                    Object[] args = new Object[] {
6398                                                    socialRequestModelImpl.getUuid(),
6399                                                    socialRequestModelImpl.getGroupId()
6400                                            };
6401    
6402                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6403                                            Long.valueOf(1));
6404                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
6405                                            socialRequestModelImpl);
6406                            }
6407    
6408                            if ((socialRequestModelImpl.getColumnBitmask() &
6409                                            FINDER_PATH_FETCH_BY_U_C_C_T_R.getColumnBitmask()) != 0) {
6410                                    Object[] args = new Object[] {
6411                                                    socialRequestModelImpl.getUserId(),
6412                                                    socialRequestModelImpl.getClassNameId(),
6413                                                    socialRequestModelImpl.getClassPK(),
6414                                                    socialRequestModelImpl.getType(),
6415                                                    socialRequestModelImpl.getReceiverUserId()
6416                                            };
6417    
6418                                    finderCache.putResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args,
6419                                            Long.valueOf(1));
6420                                    finderCache.putResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args,
6421                                            socialRequestModelImpl);
6422                            }
6423                    }
6424            }
6425    
6426            protected void clearUniqueFindersCache(
6427                    SocialRequestModelImpl socialRequestModelImpl) {
6428                    Object[] args = new Object[] {
6429                                    socialRequestModelImpl.getUuid(),
6430                                    socialRequestModelImpl.getGroupId()
6431                            };
6432    
6433                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6434                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6435    
6436                    if ((socialRequestModelImpl.getColumnBitmask() &
6437                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6438                            args = new Object[] {
6439                                            socialRequestModelImpl.getOriginalUuid(),
6440                                            socialRequestModelImpl.getOriginalGroupId()
6441                                    };
6442    
6443                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6444                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6445                    }
6446    
6447                    args = new Object[] {
6448                                    socialRequestModelImpl.getUserId(),
6449                                    socialRequestModelImpl.getClassNameId(),
6450                                    socialRequestModelImpl.getClassPK(),
6451                                    socialRequestModelImpl.getType(),
6452                                    socialRequestModelImpl.getReceiverUserId()
6453                            };
6454    
6455                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args);
6456                    finderCache.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args);
6457    
6458                    if ((socialRequestModelImpl.getColumnBitmask() &
6459                                    FINDER_PATH_FETCH_BY_U_C_C_T_R.getColumnBitmask()) != 0) {
6460                            args = new Object[] {
6461                                            socialRequestModelImpl.getOriginalUserId(),
6462                                            socialRequestModelImpl.getOriginalClassNameId(),
6463                                            socialRequestModelImpl.getOriginalClassPK(),
6464                                            socialRequestModelImpl.getOriginalType(),
6465                                            socialRequestModelImpl.getOriginalReceiverUserId()
6466                                    };
6467    
6468                            finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_R, args);
6469                            finderCache.removeResult(FINDER_PATH_FETCH_BY_U_C_C_T_R, args);
6470                    }
6471            }
6472    
6473            /**
6474             * Creates a new social request with the primary key. Does not add the social request to the database.
6475             *
6476             * @param requestId the primary key for the new social request
6477             * @return the new social request
6478             */
6479            @Override
6480            public SocialRequest create(long requestId) {
6481                    SocialRequest socialRequest = new SocialRequestImpl();
6482    
6483                    socialRequest.setNew(true);
6484                    socialRequest.setPrimaryKey(requestId);
6485    
6486                    String uuid = PortalUUIDUtil.generate();
6487    
6488                    socialRequest.setUuid(uuid);
6489    
6490                    socialRequest.setCompanyId(companyProvider.getCompanyId());
6491    
6492                    return socialRequest;
6493            }
6494    
6495            /**
6496             * Removes the social request with the primary key from the database. Also notifies the appropriate model listeners.
6497             *
6498             * @param requestId the primary key of the social request
6499             * @return the social request that was removed
6500             * @throws NoSuchRequestException if a social request with the primary key could not be found
6501             */
6502            @Override
6503            public SocialRequest remove(long requestId) throws NoSuchRequestException {
6504                    return remove((Serializable)requestId);
6505            }
6506    
6507            /**
6508             * Removes the social request with the primary key from the database. Also notifies the appropriate model listeners.
6509             *
6510             * @param primaryKey the primary key of the social request
6511             * @return the social request that was removed
6512             * @throws NoSuchRequestException if a social request with the primary key could not be found
6513             */
6514            @Override
6515            public SocialRequest remove(Serializable primaryKey)
6516                    throws NoSuchRequestException {
6517                    Session session = null;
6518    
6519                    try {
6520                            session = openSession();
6521    
6522                            SocialRequest socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
6523                                            primaryKey);
6524    
6525                            if (socialRequest == null) {
6526                                    if (_log.isDebugEnabled()) {
6527                                            _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6528                                    }
6529    
6530                                    throw new NoSuchRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6531                                            primaryKey);
6532                            }
6533    
6534                            return remove(socialRequest);
6535                    }
6536                    catch (NoSuchRequestException nsee) {
6537                            throw nsee;
6538                    }
6539                    catch (Exception e) {
6540                            throw processException(e);
6541                    }
6542                    finally {
6543                            closeSession(session);
6544                    }
6545            }
6546    
6547            @Override
6548            protected SocialRequest removeImpl(SocialRequest socialRequest) {
6549                    socialRequest = toUnwrappedModel(socialRequest);
6550    
6551                    Session session = null;
6552    
6553                    try {
6554                            session = openSession();
6555    
6556                            if (!session.contains(socialRequest)) {
6557                                    socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
6558                                                    socialRequest.getPrimaryKeyObj());
6559                            }
6560    
6561                            if (socialRequest != null) {
6562                                    session.delete(socialRequest);
6563                            }
6564                    }
6565                    catch (Exception e) {
6566                            throw processException(e);
6567                    }
6568                    finally {
6569                            closeSession(session);
6570                    }
6571    
6572                    if (socialRequest != null) {
6573                            clearCache(socialRequest);
6574                    }
6575    
6576                    return socialRequest;
6577            }
6578    
6579            @Override
6580            public SocialRequest updateImpl(SocialRequest socialRequest) {
6581                    socialRequest = toUnwrappedModel(socialRequest);
6582    
6583                    boolean isNew = socialRequest.isNew();
6584    
6585                    SocialRequestModelImpl socialRequestModelImpl = (SocialRequestModelImpl)socialRequest;
6586    
6587                    if (Validator.isNull(socialRequest.getUuid())) {
6588                            String uuid = PortalUUIDUtil.generate();
6589    
6590                            socialRequest.setUuid(uuid);
6591                    }
6592    
6593                    Session session = null;
6594    
6595                    try {
6596                            session = openSession();
6597    
6598                            if (socialRequest.isNew()) {
6599                                    session.save(socialRequest);
6600    
6601                                    socialRequest.setNew(false);
6602                            }
6603                            else {
6604                                    socialRequest = (SocialRequest)session.merge(socialRequest);
6605                            }
6606                    }
6607                    catch (Exception e) {
6608                            throw processException(e);
6609                    }
6610                    finally {
6611                            closeSession(session);
6612                    }
6613    
6614                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6615    
6616                    if (isNew || !SocialRequestModelImpl.COLUMN_BITMASK_ENABLED) {
6617                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6618                    }
6619    
6620                    else {
6621                            if ((socialRequestModelImpl.getColumnBitmask() &
6622                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6623                                    Object[] args = new Object[] {
6624                                                    socialRequestModelImpl.getOriginalUuid()
6625                                            };
6626    
6627                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6628                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6629                                            args);
6630    
6631                                    args = new Object[] { socialRequestModelImpl.getUuid() };
6632    
6633                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6634                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6635                                            args);
6636                            }
6637    
6638                            if ((socialRequestModelImpl.getColumnBitmask() &
6639                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6640                                    Object[] args = new Object[] {
6641                                                    socialRequestModelImpl.getOriginalUuid(),
6642                                                    socialRequestModelImpl.getOriginalCompanyId()
6643                                            };
6644    
6645                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6646                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6647                                            args);
6648    
6649                                    args = new Object[] {
6650                                                    socialRequestModelImpl.getUuid(),
6651                                                    socialRequestModelImpl.getCompanyId()
6652                                            };
6653    
6654                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6655                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6656                                            args);
6657                            }
6658    
6659                            if ((socialRequestModelImpl.getColumnBitmask() &
6660                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6661                                    Object[] args = new Object[] {
6662                                                    socialRequestModelImpl.getOriginalCompanyId()
6663                                            };
6664    
6665                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
6666                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6667                                            args);
6668    
6669                                    args = new Object[] { socialRequestModelImpl.getCompanyId() };
6670    
6671                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
6672                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6673                                            args);
6674                            }
6675    
6676                            if ((socialRequestModelImpl.getColumnBitmask() &
6677                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
6678                                    Object[] args = new Object[] {
6679                                                    socialRequestModelImpl.getOriginalUserId()
6680                                            };
6681    
6682                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
6683                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
6684                                            args);
6685    
6686                                    args = new Object[] { socialRequestModelImpl.getUserId() };
6687    
6688                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
6689                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
6690                                            args);
6691                            }
6692    
6693                            if ((socialRequestModelImpl.getColumnBitmask() &
6694                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID.getColumnBitmask()) != 0) {
6695                                    Object[] args = new Object[] {
6696                                                    socialRequestModelImpl.getOriginalReceiverUserId()
6697                                            };
6698    
6699                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
6700                                            args);
6701                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
6702                                            args);
6703    
6704                                    args = new Object[] { socialRequestModelImpl.getReceiverUserId() };
6705    
6706                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_RECEIVERUSERID,
6707                                            args);
6708                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RECEIVERUSERID,
6709                                            args);
6710                            }
6711    
6712                            if ((socialRequestModelImpl.getColumnBitmask() &
6713                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S.getColumnBitmask()) != 0) {
6714                                    Object[] args = new Object[] {
6715                                                    socialRequestModelImpl.getOriginalUserId(),
6716                                                    socialRequestModelImpl.getOriginalStatus()
6717                                            };
6718    
6719                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_S, args);
6720                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S,
6721                                            args);
6722    
6723                                    args = new Object[] {
6724                                                    socialRequestModelImpl.getUserId(),
6725                                                    socialRequestModelImpl.getStatus()
6726                                            };
6727    
6728                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_S, args);
6729                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_S,
6730                                            args);
6731                            }
6732    
6733                            if ((socialRequestModelImpl.getColumnBitmask() &
6734                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
6735                                    Object[] args = new Object[] {
6736                                                    socialRequestModelImpl.getOriginalClassNameId(),
6737                                                    socialRequestModelImpl.getOriginalClassPK()
6738                                            };
6739    
6740                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
6741                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
6742                                            args);
6743    
6744                                    args = new Object[] {
6745                                                    socialRequestModelImpl.getClassNameId(),
6746                                                    socialRequestModelImpl.getClassPK()
6747                                            };
6748    
6749                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
6750                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
6751                                            args);
6752                            }
6753    
6754                            if ((socialRequestModelImpl.getColumnBitmask() &
6755                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S.getColumnBitmask()) != 0) {
6756                                    Object[] args = new Object[] {
6757                                                    socialRequestModelImpl.getOriginalReceiverUserId(),
6758                                                    socialRequestModelImpl.getOriginalStatus()
6759                                            };
6760    
6761                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
6762                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
6763                                            args);
6764    
6765                                    args = new Object[] {
6766                                                    socialRequestModelImpl.getReceiverUserId(),
6767                                                    socialRequestModelImpl.getStatus()
6768                                            };
6769    
6770                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_R_S, args);
6771                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_R_S,
6772                                            args);
6773                            }
6774    
6775                            if ((socialRequestModelImpl.getColumnBitmask() &
6776                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S.getColumnBitmask()) != 0) {
6777                                    Object[] args = new Object[] {
6778                                                    socialRequestModelImpl.getOriginalUserId(),
6779                                                    socialRequestModelImpl.getOriginalClassNameId(),
6780                                                    socialRequestModelImpl.getOriginalClassPK(),
6781                                                    socialRequestModelImpl.getOriginalType(),
6782                                                    socialRequestModelImpl.getOriginalStatus()
6783                                            };
6784    
6785                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_S, args);
6786                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S,
6787                                            args);
6788    
6789                                    args = new Object[] {
6790                                                    socialRequestModelImpl.getUserId(),
6791                                                    socialRequestModelImpl.getClassNameId(),
6792                                                    socialRequestModelImpl.getClassPK(),
6793                                                    socialRequestModelImpl.getType(),
6794                                                    socialRequestModelImpl.getStatus()
6795                                            };
6796    
6797                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_C_C_T_S, args);
6798                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_T_S,
6799                                            args);
6800                            }
6801    
6802                            if ((socialRequestModelImpl.getColumnBitmask() &
6803                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S.getColumnBitmask()) != 0) {
6804                                    Object[] args = new Object[] {
6805                                                    socialRequestModelImpl.getOriginalClassNameId(),
6806                                                    socialRequestModelImpl.getOriginalClassPK(),
6807                                                    socialRequestModelImpl.getOriginalType(),
6808                                                    socialRequestModelImpl.getOriginalReceiverUserId(),
6809                                                    socialRequestModelImpl.getOriginalStatus()
6810                                            };
6811    
6812                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_T_R_S, args);
6813                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S,
6814                                            args);
6815    
6816                                    args = new Object[] {
6817                                                    socialRequestModelImpl.getClassNameId(),
6818                                                    socialRequestModelImpl.getClassPK(),
6819                                                    socialRequestModelImpl.getType(),
6820                                                    socialRequestModelImpl.getReceiverUserId(),
6821                                                    socialRequestModelImpl.getStatus()
6822                                            };
6823    
6824                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_T_R_S, args);
6825                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_T_R_S,
6826                                            args);
6827                            }
6828                    }
6829    
6830                    entityCache.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6831                            SocialRequestImpl.class, socialRequest.getPrimaryKey(),
6832                            socialRequest, false);
6833    
6834                    clearUniqueFindersCache(socialRequestModelImpl);
6835                    cacheUniqueFindersCache(socialRequestModelImpl, isNew);
6836    
6837                    socialRequest.resetOriginalValues();
6838    
6839                    return socialRequest;
6840            }
6841    
6842            protected SocialRequest toUnwrappedModel(SocialRequest socialRequest) {
6843                    if (socialRequest instanceof SocialRequestImpl) {
6844                            return socialRequest;
6845                    }
6846    
6847                    SocialRequestImpl socialRequestImpl = new SocialRequestImpl();
6848    
6849                    socialRequestImpl.setNew(socialRequest.isNew());
6850                    socialRequestImpl.setPrimaryKey(socialRequest.getPrimaryKey());
6851    
6852                    socialRequestImpl.setUuid(socialRequest.getUuid());
6853                    socialRequestImpl.setRequestId(socialRequest.getRequestId());
6854                    socialRequestImpl.setGroupId(socialRequest.getGroupId());
6855                    socialRequestImpl.setCompanyId(socialRequest.getCompanyId());
6856                    socialRequestImpl.setUserId(socialRequest.getUserId());
6857                    socialRequestImpl.setCreateDate(socialRequest.getCreateDate());
6858                    socialRequestImpl.setModifiedDate(socialRequest.getModifiedDate());
6859                    socialRequestImpl.setClassNameId(socialRequest.getClassNameId());
6860                    socialRequestImpl.setClassPK(socialRequest.getClassPK());
6861                    socialRequestImpl.setType(socialRequest.getType());
6862                    socialRequestImpl.setExtraData(socialRequest.getExtraData());
6863                    socialRequestImpl.setReceiverUserId(socialRequest.getReceiverUserId());
6864                    socialRequestImpl.setStatus(socialRequest.getStatus());
6865    
6866                    return socialRequestImpl;
6867            }
6868    
6869            /**
6870             * Returns the social request with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
6871             *
6872             * @param primaryKey the primary key of the social request
6873             * @return the social request
6874             * @throws NoSuchRequestException if a social request with the primary key could not be found
6875             */
6876            @Override
6877            public SocialRequest findByPrimaryKey(Serializable primaryKey)
6878                    throws NoSuchRequestException {
6879                    SocialRequest socialRequest = fetchByPrimaryKey(primaryKey);
6880    
6881                    if (socialRequest == null) {
6882                            if (_log.isDebugEnabled()) {
6883                                    _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6884                            }
6885    
6886                            throw new NoSuchRequestException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6887                                    primaryKey);
6888                    }
6889    
6890                    return socialRequest;
6891            }
6892    
6893            /**
6894             * Returns the social request with the primary key or throws a {@link NoSuchRequestException} if it could not be found.
6895             *
6896             * @param requestId the primary key of the social request
6897             * @return the social request
6898             * @throws NoSuchRequestException if a social request with the primary key could not be found
6899             */
6900            @Override
6901            public SocialRequest findByPrimaryKey(long requestId)
6902                    throws NoSuchRequestException {
6903                    return findByPrimaryKey((Serializable)requestId);
6904            }
6905    
6906            /**
6907             * Returns the social request with the primary key or returns <code>null</code> if it could not be found.
6908             *
6909             * @param primaryKey the primary key of the social request
6910             * @return the social request, or <code>null</code> if a social request with the primary key could not be found
6911             */
6912            @Override
6913            public SocialRequest fetchByPrimaryKey(Serializable primaryKey) {
6914                    SocialRequest socialRequest = (SocialRequest)entityCache.getResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6915                                    SocialRequestImpl.class, primaryKey);
6916    
6917                    if (socialRequest == _nullSocialRequest) {
6918                            return null;
6919                    }
6920    
6921                    if (socialRequest == null) {
6922                            Session session = null;
6923    
6924                            try {
6925                                    session = openSession();
6926    
6927                                    socialRequest = (SocialRequest)session.get(SocialRequestImpl.class,
6928                                                    primaryKey);
6929    
6930                                    if (socialRequest != null) {
6931                                            cacheResult(socialRequest);
6932                                    }
6933                                    else {
6934                                            entityCache.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6935                                                    SocialRequestImpl.class, primaryKey, _nullSocialRequest);
6936                                    }
6937                            }
6938                            catch (Exception e) {
6939                                    entityCache.removeResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6940                                            SocialRequestImpl.class, primaryKey);
6941    
6942                                    throw processException(e);
6943                            }
6944                            finally {
6945                                    closeSession(session);
6946                            }
6947                    }
6948    
6949                    return socialRequest;
6950            }
6951    
6952            /**
6953             * Returns the social request with the primary key or returns <code>null</code> if it could not be found.
6954             *
6955             * @param requestId the primary key of the social request
6956             * @return the social request, or <code>null</code> if a social request with the primary key could not be found
6957             */
6958            @Override
6959            public SocialRequest fetchByPrimaryKey(long requestId) {
6960                    return fetchByPrimaryKey((Serializable)requestId);
6961            }
6962    
6963            @Override
6964            public Map<Serializable, SocialRequest> fetchByPrimaryKeys(
6965                    Set<Serializable> primaryKeys) {
6966                    if (primaryKeys.isEmpty()) {
6967                            return Collections.emptyMap();
6968                    }
6969    
6970                    Map<Serializable, SocialRequest> map = new HashMap<Serializable, SocialRequest>();
6971    
6972                    if (primaryKeys.size() == 1) {
6973                            Iterator<Serializable> iterator = primaryKeys.iterator();
6974    
6975                            Serializable primaryKey = iterator.next();
6976    
6977                            SocialRequest socialRequest = fetchByPrimaryKey(primaryKey);
6978    
6979                            if (socialRequest != null) {
6980                                    map.put(primaryKey, socialRequest);
6981                            }
6982    
6983                            return map;
6984                    }
6985    
6986                    Set<Serializable> uncachedPrimaryKeys = null;
6987    
6988                    for (Serializable primaryKey : primaryKeys) {
6989                            SocialRequest socialRequest = (SocialRequest)entityCache.getResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
6990                                            SocialRequestImpl.class, primaryKey);
6991    
6992                            if (socialRequest == null) {
6993                                    if (uncachedPrimaryKeys == null) {
6994                                            uncachedPrimaryKeys = new HashSet<Serializable>();
6995                                    }
6996    
6997                                    uncachedPrimaryKeys.add(primaryKey);
6998                            }
6999                            else {
7000                                    map.put(primaryKey, socialRequest);
7001                            }
7002                    }
7003    
7004                    if (uncachedPrimaryKeys == null) {
7005                            return map;
7006                    }
7007    
7008                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
7009                                    1);
7010    
7011                    query.append(_SQL_SELECT_SOCIALREQUEST_WHERE_PKS_IN);
7012    
7013                    for (Serializable primaryKey : uncachedPrimaryKeys) {
7014                            query.append(String.valueOf(primaryKey));
7015    
7016                            query.append(StringPool.COMMA);
7017                    }
7018    
7019                    query.setIndex(query.index() - 1);
7020    
7021                    query.append(StringPool.CLOSE_PARENTHESIS);
7022    
7023                    String sql = query.toString();
7024    
7025                    Session session = null;
7026    
7027                    try {
7028                            session = openSession();
7029    
7030                            Query q = session.createQuery(sql);
7031    
7032                            for (SocialRequest socialRequest : (List<SocialRequest>)q.list()) {
7033                                    map.put(socialRequest.getPrimaryKeyObj(), socialRequest);
7034    
7035                                    cacheResult(socialRequest);
7036    
7037                                    uncachedPrimaryKeys.remove(socialRequest.getPrimaryKeyObj());
7038                            }
7039    
7040                            for (Serializable primaryKey : uncachedPrimaryKeys) {
7041                                    entityCache.putResult(SocialRequestModelImpl.ENTITY_CACHE_ENABLED,
7042                                            SocialRequestImpl.class, primaryKey, _nullSocialRequest);
7043                            }
7044                    }
7045                    catch (Exception e) {
7046                            throw processException(e);
7047                    }
7048                    finally {
7049                            closeSession(session);
7050                    }
7051    
7052                    return map;
7053            }
7054    
7055            /**
7056             * Returns all the social requests.
7057             *
7058             * @return the social requests
7059             */
7060            @Override
7061            public List<SocialRequest> findAll() {
7062                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7063            }
7064    
7065            /**
7066             * Returns a range of all the social requests.
7067             *
7068             * <p>
7069             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7070             * </p>
7071             *
7072             * @param start the lower bound of the range of social requests
7073             * @param end the upper bound of the range of social requests (not inclusive)
7074             * @return the range of social requests
7075             */
7076            @Override
7077            public List<SocialRequest> findAll(int start, int end) {
7078                    return findAll(start, end, null);
7079            }
7080    
7081            /**
7082             * Returns an ordered range of all the social requests.
7083             *
7084             * <p>
7085             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7086             * </p>
7087             *
7088             * @param start the lower bound of the range of social requests
7089             * @param end the upper bound of the range of social requests (not inclusive)
7090             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7091             * @return the ordered range of social requests
7092             */
7093            @Override
7094            public List<SocialRequest> findAll(int start, int end,
7095                    OrderByComparator<SocialRequest> orderByComparator) {
7096                    return findAll(start, end, orderByComparator, true);
7097            }
7098    
7099            /**
7100             * Returns an ordered range of all the social requests.
7101             *
7102             * <p>
7103             * 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 QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link SocialRequestModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7104             * </p>
7105             *
7106             * @param start the lower bound of the range of social requests
7107             * @param end the upper bound of the range of social requests (not inclusive)
7108             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7109             * @param retrieveFromCache whether to retrieve from the finder cache
7110             * @return the ordered range of social requests
7111             */
7112            @Override
7113            public List<SocialRequest> findAll(int start, int end,
7114                    OrderByComparator<SocialRequest> orderByComparator,
7115                    boolean retrieveFromCache) {
7116                    boolean pagination = true;
7117                    FinderPath finderPath = null;
7118                    Object[] finderArgs = null;
7119    
7120                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7121                                    (orderByComparator == null)) {
7122                            pagination = false;
7123                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7124                            finderArgs = FINDER_ARGS_EMPTY;
7125                    }
7126                    else {
7127                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7128                            finderArgs = new Object[] { start, end, orderByComparator };
7129                    }
7130    
7131                    List<SocialRequest> list = null;
7132    
7133                    if (retrieveFromCache) {
7134                            list = (List<SocialRequest>)finderCache.getResult(finderPath,
7135                                            finderArgs, this);
7136                    }
7137    
7138                    if (list == null) {
7139                            StringBundler query = null;
7140                            String sql = null;
7141    
7142                            if (orderByComparator != null) {
7143                                    query = new StringBundler(2 +
7144                                                    (orderByComparator.getOrderByFields().length * 2));
7145    
7146                                    query.append(_SQL_SELECT_SOCIALREQUEST);
7147    
7148                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7149                                            orderByComparator);
7150    
7151                                    sql = query.toString();
7152                            }
7153                            else {
7154                                    sql = _SQL_SELECT_SOCIALREQUEST;
7155    
7156                                    if (pagination) {
7157                                            sql = sql.concat(SocialRequestModelImpl.ORDER_BY_JPQL);
7158                                    }
7159                            }
7160    
7161                            Session session = null;
7162    
7163                            try {
7164                                    session = openSession();
7165    
7166                                    Query q = session.createQuery(sql);
7167    
7168                                    if (!pagination) {
7169                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
7170                                                            start, end, false);
7171    
7172                                            Collections.sort(list);
7173    
7174                                            list = Collections.unmodifiableList(list);
7175                                    }
7176                                    else {
7177                                            list = (List<SocialRequest>)QueryUtil.list(q, getDialect(),
7178                                                            start, end);
7179                                    }
7180    
7181                                    cacheResult(list);
7182    
7183                                    finderCache.putResult(finderPath, finderArgs, list);
7184                            }
7185                            catch (Exception e) {
7186                                    finderCache.removeResult(finderPath, finderArgs);
7187    
7188                                    throw processException(e);
7189                            }
7190                            finally {
7191                                    closeSession(session);
7192                            }
7193                    }
7194    
7195                    return list;
7196            }
7197    
7198            /**
7199             * Removes all the social requests from the database.
7200             *
7201             */
7202            @Override
7203            public void removeAll() {
7204                    for (SocialRequest socialRequest : findAll()) {
7205                            remove(socialRequest);
7206                    }
7207            }
7208    
7209            /**
7210             * Returns the number of social requests.
7211             *
7212             * @return the number of social requests
7213             */
7214            @Override
7215            public int countAll() {
7216                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
7217                                    FINDER_ARGS_EMPTY, this);
7218    
7219                    if (count == null) {
7220                            Session session = null;
7221    
7222                            try {
7223                                    session = openSession();
7224    
7225                                    Query q = session.createQuery(_SQL_COUNT_SOCIALREQUEST);
7226    
7227                                    count = (Long)q.uniqueResult();
7228    
7229                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
7230                                            count);
7231                            }
7232                            catch (Exception e) {
7233                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
7234                                            FINDER_ARGS_EMPTY);
7235    
7236                                    throw processException(e);
7237                            }
7238                            finally {
7239                                    closeSession(session);
7240                            }
7241                    }
7242    
7243                    return count.intValue();
7244            }
7245    
7246            @Override
7247            public Set<String> getBadColumnNames() {
7248                    return _badColumnNames;
7249            }
7250    
7251            @Override
7252            protected Map<String, Integer> getTableColumnsMap() {
7253                    return SocialRequestModelImpl.TABLE_COLUMNS_MAP;
7254            }
7255    
7256            /**
7257             * Initializes the social request persistence.
7258             */
7259            public void afterPropertiesSet() {
7260            }
7261    
7262            public void destroy() {
7263                    entityCache.removeCache(SocialRequestImpl.class.getName());
7264                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
7265                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7266                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7267            }
7268    
7269            @BeanReference(type = CompanyProviderWrapper.class)
7270            protected CompanyProvider companyProvider;
7271            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
7272            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
7273            private static final String _SQL_SELECT_SOCIALREQUEST = "SELECT socialRequest FROM SocialRequest socialRequest";
7274            private static final String _SQL_SELECT_SOCIALREQUEST_WHERE_PKS_IN = "SELECT socialRequest FROM SocialRequest socialRequest WHERE requestId IN (";
7275            private static final String _SQL_SELECT_SOCIALREQUEST_WHERE = "SELECT socialRequest FROM SocialRequest socialRequest WHERE ";
7276            private static final String _SQL_COUNT_SOCIALREQUEST = "SELECT COUNT(socialRequest) FROM SocialRequest socialRequest";
7277            private static final String _SQL_COUNT_SOCIALREQUEST_WHERE = "SELECT COUNT(socialRequest) FROM SocialRequest socialRequest WHERE ";
7278            private static final String _ORDER_BY_ENTITY_ALIAS = "socialRequest.";
7279            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No SocialRequest exists with the primary key ";
7280            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No SocialRequest exists with the key {";
7281            private static final Log _log = LogFactoryUtil.getLog(SocialRequestPersistenceImpl.class);
7282            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
7283                                    "uuid", "type"
7284                            });
7285            private static final SocialRequest _nullSocialRequest = new SocialRequestImpl() {
7286                            @Override
7287                            public Object clone() {
7288                                    return this;
7289                            }
7290    
7291                            @Override
7292                            public CacheModel<SocialRequest> toCacheModel() {
7293                                    return _nullSocialRequestCacheModel;
7294                            }
7295                    };
7296    
7297            private static final CacheModel<SocialRequest> _nullSocialRequestCacheModel = new CacheModel<SocialRequest>() {
7298                            @Override
7299                            public SocialRequest toEntityModel() {
7300                                    return _nullSocialRequest;
7301                            }
7302                    };
7303    }