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