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