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