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