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