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