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