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